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

CSS样式表
网页设计中谨慎使用CSS sprites
CSS教程:清除浮动方法大全
CSS教程:伪清除浮动
网页布局教程:边距和绝对定位
CSS教程:论CSS选择器的浏览器支持
如何在CSS中设定文本的尺寸
CSS网页布局应该避免滥用div元素
CSS教程:CSS定位属性
CSS网页布局教程:层叠加的5条原则
css字体设置(不同浏览器设置效果)
CSS教程:15个必须阅读的CSS入门文章
IE6下注释引起的文字溢出和浮动错位
CSS教程:语义化标记抛弃DIV标记
不再使用class和id进行网页布局
利用CSS3定位页面元素
CSS网页布局实例:三栏等高布局
CSS实例:日期垂直排列的两种技巧
css教程:font-size属性
CSS教程:认真学习haslayout
CSS教程:认识CSS初始化(重设浏览器的样式)

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


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