2010-08-09 65 views
5

我试图做这样的事情:CSS:浮法图像的左边 - 问题

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

回答

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

不错!非常感谢! – Fuxi 2010-08-09 11:55:53

3

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

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

这也是一个有效的解决方案,但它使标记复杂化。我遇到了溢出技巧不适合我的需求的情况,并且具有'clear:both'的'div'是必要的。 – 2010-08-09 12:25:09

+0

@RyanKinal然后使用clearfix。 – pilau 2012-11-12 09:21:55

1

< DIV风格= “溢出:汽车” > </DIV >