您的位置:首页 > 运维架构

FF浏览器嵌套div中margin-top转移问题的解决办法

2011-10-14 17:20 316 查看
 嵌套div中margin-top转移问题的解决办法

在这两个浏览器中,有两个嵌套关系的div,如果外层div的父元素padding值为0,那么内层div的margin-top或者margin-bottom的值会“转移”给外层div。

以上边缘为例:

<div style="background-color:green; color:white;" >绿色</div>

<div style="background-color: black;height:300px; padding-top:0px;">

<div style="background-color: black;height:300px;">

<!--解决方法代码start--><!--解决方法代码end-->

   <div style="margin-top:50px;height:150px; background-color:red; color:white;">红色</div>

</div>

</div>

在Firefox和IE8中绿色和红色div之间会有50px的白色空隙,而在IE中则为黑色。

解决方法有这么几种,下面我只列出3种:

1.在注释那里插入一个非空的元素<div style="height:0px"> </div>

2.把黑色的div加入padding-top属性代替margin-top

3.第一种最好,第二种不错,第三种不太推荐,就是在黑色div加入属性border等于1px,记得也要加入solid哦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  div 浏览器 firefox border ie