当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > margin 负值引起的层级(z-index)问题

CSS样式表
网页布局教程:掌握CSS网页布局属性
WEB标准的CSS网页布局技巧5则
你怎么书写CSS代码?
CSS教程:表单元素不继承body的字体属性
调整CSS的方式给滚动条换色
CSS网页布局中表格制作实例
网页设计学习教程:CSS盒模型
网页制作学习教程:CSS Position
网页九宫格布局:应用透明的外圆角
CSS网页布局学习的参考诀窍
把网页按钮伪装成超链接
CSS教程:检验CSS书写是否标准合理
你的网页最好通过HTML校验和CSS校验
网页制作教程:CSS的好处
网页制作心得:分离之后怎么做?
CSS教程:数字和字母将容器撑大问题解决
CSS Sprites优化网页代码的方法
CSS实例:精简代码的兼容各浏览器的滑动门
CSS网页制作技巧:提高CSS可阅读性
英文教程:CSS的Float

CSS样式表 中的 margin 负值引起的层级(z-index)问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 321 ::
收藏到网摘: n/a

先来看这么一段代码:

代码如下:

<div style="height:100px;width:200px; border: solid 1px black; ">
<div style="background-color:Red;margin-top: -5px " mce_style="background-color:Red;margin-top: -5px ">
<a href="http://www.ruanchen.com/" mce_href="http://www.ruanchen.com/">软晨学习网</a></div>
</div>

IE6和IE7下,内层的容器被外层覆盖,如图所示:

在IE8和ff下,外层的容器被内层覆盖,如图所示:

真是疯狂啊,如果要达到IE8的外层的容器被内层覆盖的效果,ie7可以通过触发内层的layout解决,,但是IE6却不行,只能在内层使用position:relative来解决问题,当然position:relative也解决ie7的问题,因为position:relative本身就能触发layout。
看代码:

代码如下:

<div style="height:100px;width:200px; border: solid 1px black; ">
<div style="background-color:Red;margin-top: -5px;position:relative" mce_style="background-color:Red;margin-top: -5px;position:relative">
<a href="http://www.ruanchen.com/" mce_href="http://www.ruanchen.com/">软晨学习网</a> </div>
</div>

当然要IE8、FF达到IE6、IE7的效果就只要在外层加overflow:hidden 就可以了,看代码

代码如下:

<div style="height:100px;width:200px; border: solid 1px black; overflow:hidden ">
<div style="background-color:Red;margin-top: -5px;" mce_style="background-color:Red;margin-top: -5px;">
<a href="http://www.ruanchen.com/" mce_href="http://www.ruanchen.com/">软晨学习网</a> </div>
</div>