CSS 中将图像浮动到左侧

问题描述 投票:0回答:3

我正在尝试做类似的事情:

--------------------------------------------
| --------- 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 容器的最小高度。

css image css-float
3个回答
5
投票
div {
    overflow: hidden;  /* except IE6 */
    display: inline-block; /* IE6 */
}
div {
    display: block; /* IE6 */
}

4
投票

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

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

1
投票

© www.soinside.com 2019 - 2024. All rights reserved.