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

CSS样式表
提高网页效率的14条注意事项图文
提高网页的效率 Use YSlow to know why your web Slow
学习WEB标准总结的一些CSS/XHTML知识小结
CSS文件可维护、可读性提高指南
Firefox下样式设置宽度奇怪现象
Chrome的hack写法以及CSS的支持程度图示
IE6支持position:fixed完美解决方法
css为图片设置背景图片
ASP、PHP与javascript根据时段自动切换CSS皮肤的代码
css图片切换效果代码[不用js]
css import与link的区别
BS项目中的CSS架构_仅加载自己需要的CSS
div结合css布局bbs首页(div+css布局入门)
css 兼容性问题this.style.cursor=''''hand''''
CSS渐变统计柱形图
跨浏览器的实践:position:fixed 层的固定定位
标准布局常见问题及解决办法
css美化input file按钮的代码方法
重置默认样式 css reset
支持IE6 IE7 Firefox 的纯CSS的下拉菜单

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


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