2010-08-09 59 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 >