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

CSS样式表
用div+css模拟表格对角线
10个HTML和CSS代码修正IE6问题的方法
IE6因为编码问题无法正确解析CSS
3G时代 移动WEB设计资料WAP
内联元素是什么意思呢?什么是块级别元素
初学者需要知道WEB标准的前景
CSS网页布局id和class类的命名介绍
快速定位到复杂的CSS BUG问题
学完CSS后该学什么?
CSS实例:鼠标滑过文字超级链接背景变色
CSS教程:所有浏览器中都能正常显示的字体
如何用css控制input中的text和radio
浏览器处理网页字体效果对比
网页制作学习:reflow概念
CSS样式表的hack的写作方法
CSS代码优化的两个原因
解决父容器透明子容器不透明继承问题
网页制作学习:reflow的问题
CSS实现透明效果颜色的方法:RGBa
DIV+CSS制作网页心得

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


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