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

CSS样式表
css分页样式代码
用css filter做鼠标滑过图片效果
有关于IE8 Beta 1两个提醒
css Hspace 和vspace的图片控制实例
firefox background-image垂直平铺问题的解决方法
发一个css比较清爽的写法
htm页面中<a name>加name和id的冲突附解决方法
javascript 获取特定的 CSS属性值
CSS教程之CSS的应用
html页面head区域的编码书写规范
html滚动条样式
不用图片作背景CSS做的小灯笼效果_练习用
网页绿色系配色应用实例图文
网页中英文混排行高不等问题的解决方法
CSS Hack 汇总速查手册浏览器兼容必会
css文本框与按钮美化效果代码
网页设计中的 serif 和 sans-serif字体应用
采用XHTML和CSS设计可重用可换肤的WEB站点的方法
CSS 浏览器的等宽空格问题解决
欲练CSS ,必先解决IE的一些细节分析

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


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