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

CSS样式表
line-height使文本居中的3像素bug问题
IE8.0Beta比较不错的功能:WebSlices
IE8、IE7、IE6、FF简单的CSS HACK测试
Web前端开发的Firefox插件
CSS3教程:background-clip和background-origin
CSS教程:使用ul进行网页的多列布局
CSS盒模型制定网页的宽度和高度的原理
CSS:何制作一个向各个方向延展box?
CSS高级技巧:CSS Sprites
CSS高级技巧:图片替换
CSS高级技巧:文字环绕图片
CSS样式表教程:screen媒体类型的作用
css教程:美化网页段落的排版
网页注册表单的网页设计技巧
CSS控制表格文字样式的研究
dl,dt,dd,ul,li,ol区别及应用
英文教程:鼠标悬停(hover)效果
CSS制作的三款漂亮的网页表单
CSS教程:行高line-height属性(2)
CSS:闭合元素和浮动元素的差别

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


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