FF里,要在外层的div里放float:left和float:right的div,需要设置外层div的高度。
你可以试一下:
<div style="background:#F00;width:700px;">
<div style="background:#FFF;float:left;width:200px;height:100px;">DIV1</div>
<div style="background:#FFF;float:right;width:200px;height:100px;">DIV2</div>
</div>
在IE里正常,在FF里,不会有红色背景,也就是外层div没有被撑开。
<div style="background:#F00;width:700px;height:100px;">
<div style="background:#FFF;float:left;width:200px;height:100px;">DIV1</div>
<div style="background:#FFF;float:right;width:200px;height:100px;">DIV2</div>
</div>
这样就正常了。
最好外层和里层的DIV都定义高度和宽度。这样不太容易出现问题。
如果实在是外层DIV不能确定高度,那么定义一个CSS类:
.box:after {
content: ".";
display: block;
height: 0px;
clear: both;
visibility: hidden;
}
/* Hides from IE-mac /*/
* html .box {height: 1%;}
/* End hide from IE-mac */
在外层DIV里class="box",也可以。
做过很多DIV+CSS站点,一般我都是定义高度和宽度,这样基本上在所有的浏览器里都不会有什么问题了。为了防止DIV里面的东西太多撑开,最好是多用用overflow:hidden。
关于firefox不兼容DIV嵌套的问题
最新推荐文章于 2023-08-30 09:00:56 发布