2013-02-16 28 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> 
相关问题