在CSS中将图像向左浮动

ubof19bj  于 9个月前  发布在  其他
关注(0)|答案(3)|浏览(89)

我想做的是:

--------------------------------------------
| --------- text text text text text text  |
| | image | text text text text text text  |
| |       | text text text text text text  |
| |       | text text text text text text  |
| --------- text text text text text text  |
| text text text text text text text text  |
| text text text text text text text text  |
--------------------------------------------

字符串
标记应该是正确的:

<div>
    <img src='myimage.jpg' style='float:left;'>
    tex text text ..
</div>


问题是-如果只有几个文本,图像将从容器div中“浮动”出来,看起来像这样:

--------------------------------------------
| --------- text text text text text text  |
| | image | text text text text text text  |
|_|       |________________________________|
  |       |
  ---------


我该如何解决这个问题?对我来说唯一的解决方案似乎是设置div容器的min-height。

cyej8jka

cyej8jka1#

div {
    overflow: hidden;  /* except IE6 */
    display: inline-block; /* IE6 */
}
div {
    display: block; /* IE6 */
}

字符串

qhhrdooz

qhhrdooz2#

style="clear:both;元素的末尾添加一个空元素,就像这样:

<div>
    <img src='myimage.jpg' style='float:left;'>
    tex text text ..
    <div style="clear:both;"></div>
</div>

字符串

相关问题