2013-02-16 43 views

回答

3

使用overflow風格父,沒有specifing大小父:

<div style="background:#111;overflow:hidden;"> 
    <div id="a" style="float:left; height:30px"></div> 
</div> 
+0

omg的工作!但爲什麼會這樣:O? – 2013-02-16 14:02:53

+1

添加'overflow:hidden'會導致瀏覽器清除元素末尾的所有浮點數。這包括其中的浮標,因此將它們集中在一起。非常方便知道! – 2013-02-16 14:06:10

+0

太棒了! – 2013-02-16 14:07:20

1

插入<div style="clear:both"></div>右後的 「#A」 的div

1

浮動沒有按元素」不會影響父母的維度。您需要添加一個清除元件,即元素與clear規則設置爲both,像這樣:

<div style="background:#111"> 
    <div id="a" style="float:left; height:30px"></div> 
    <div style="clear:both"></div> 
</div>