FF浏览器嵌套div中margin-top转移问题的解决办法
2011-06-28 17:15
302 查看
嵌套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,如果外层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中margin-top转移问题的解决办法
- FF浏览器嵌套div中margin-top转移问题的解决办法
- FF浏览器嵌套div中margin-top转移问题的解决办法
- 整理:firefox的margin-top问题解决办法
- div嵌套内层div的margin-top转移给外层div的解决办法
- firefox margin-top失效的原因与解决办法
- 子DIV块中设置margin-top时影响父DIV块位置的解决办法
- 第一个子容器设置margin-top后和父容器发生外边距合并,解决办法是给父容器设置非0 padding-top或overflow:hidden
- Css中margin塌陷与合并问题与解决办法
- IE6 / IE7 / Firefox 的margin问题解决办法
- margin叠加问题及解决办法
- CSS中margin-top属性失效问题解决
- 子div块中设置margin-top时影响父div块位置的解决办法及其原因
- FF下子div的margin-top被传递给父div的解决办法
- SQL Server中TOP子句可能导致的问题以及解决办法
- firefox,IE8中margin-top的bug及解决办法
- 关于IE6/IE7中浮动元素margin-bottom值失效的问题解决办法。
- 给子元素盒子一个垂直外边距margin-top,父元素盒子也会往下走margin-top的值的解决办法
- 子div块中设置margin-top时影响父div块位置的解决办法及其原因
- CSS中,margin-top塌陷问题的解决