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

CSS样式表
DIV和CSS排版中制作细线条的方法小结
在解决ul居中问题时想到的几点
网页编辑中CSS样式表技巧总结
一个老外弄的Clearing floats(清除浮动的方法)
常用的DIV+CSS的基本框架结构但不推荐都放一个div里
无js5款纯div+css制作的弹出菜单标准
超强推荐CSS打造经典鼠标触发显示选项
CSS网页布局入门教程5:二列宽度自适应
CSS网页布局入门教程6:左列固定,右列宽度自适应
CSS网页布局入门教程7:二列固定宽度居中
CSS网页布局入门教程9:用CSS设计网站导航——横向导航
CSS网页布局入门教程10:带当前标识的标签式横向导航
CSS网页布局入门教程11:带当前标识的标签式横向导航图片美化版
CSS网页布局入门教程12:纵向导航菜单
CSS网页布局入门教程13:下拉及多级弹出式菜单
CSS网页布局入门教程14:纵向下拉及多级弹出式菜单
解读css发展历史
让用户自己控制网页字体的大小的css书写方法
CSS注释、命名、继承性、样式排序等CSS技巧的小结
CSS标签切换代码实例教程 比较漂亮

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


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