【发布时间】:2014-10-14 10:11:25
【问题描述】:
我有一个问题:
- 为什么下面的HTML代码的输出是这样的?
代码如下:
<div style="width: 500px; float: left; border-style: solid; padding-left: 10px;">This box occupies 516 pixels on the browser window</div>
<div style="width: 400px; float: left; border-style: solid; padding-left: 10px; margin-left: 50px;">This box occupies 466 pixels of the browser window</div>
<div style="width: 966px; border-style: solid; padding-left: 10px;">This box occupies 982 pixels of the browser window</div>
我希望第三个 div 应该出现在其他两个浮动 div 下,但它看起来像是包含它们?
我是否以错误的方式使用了 float 属性?
附:我正在使用 Mozilla Firefox 作为浏览器。
谢谢
【问题讨论】:
-
好的,我想我必须在第三个 div 中使用 clear:left 属性?但是为什么我不使用 clear:left 时会有这个奇怪的框?
-
谢谢 Hashem,你能解释一下为什么我不使用 clear:left 时会有这样的输出吗?
-
这只是 I've explained it fully here 的 CSS 浮动的预期行为。事实上,线框尊重浮动元素,所以它们会包裹它,盒子本身会忽略浮动元素。
标签: html css css-float stylesheet