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

CSS样式表
CSS网页布局学习之Font-size的妙用
CSS实例教程:网页区块中标题右侧更多
CSS教程(1):学习CSS背景相关知识
CSS教程(4):通过实例学习CSS背景
CSS教程(5):通过实例学习CSS背景
极酷的三层分离的标准滑动门导航菜单
网页版Firebug
CSS实例:CSS实现的等高网页布局
CSS教程:CSS3圆角属性
CSS教程:制作对用户友好的站内搜索表单
IE盒子模型和标准W3C盒子模型
CSS外边距叠加的问题,CSS教程
IE8的一些有趣的新功能
CSS高级技巧:滑动门技术
CSS设计网页边框的几个实例
雅黑字体对IE中的网页布局的影响
CSS技巧:改善代码可读性并简化代码管理
吸引用户点击的按钮设计以及网页按钮实例
CSS实例:超酷的网站导航按钮
CSS实例:创建一个鼠标感应换图片的按钮

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 295 ::
收藏到网摘: 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>