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

CSS样式表
Pjblog模板制作教程 超强推荐
(X)HTML Strict 下的嵌套规则
BUTTON和INPUT的区别
css 命名规范
各浏览器padding、margin的差异
IE浮动边界BUG延伸探讨
激发你的灵感:50个优秀的Favicons
Lesson01_08 图像地图
Lesson03_01 什么是CSS和CSS的设置方式
[转]Accesskey引起的一点点思考
CSS仿淘宝首页导航条布局效果
Css利用js的expression实现的效果
Web标准学习资源(书籍、网站)推荐
DIV+CSS 滑动门技术的简单例子
给自己的网站制作一个favicon.ico图标的实现方法
100%点击区的滑动门代码
用js实现的DIV+CSS编辑器代码
css条件注释理论及实践源文件
CSS条件注释的使用详解教材
针对浏览器隐藏CSS之独孤九剑

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


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