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

CSS样式表
CSS定位中Positoin、absolute、Relative的一些研究
脚本控制三行三列自适应高度DIV布局的代码
word-wrap在firefox中不起作用的解决方法
网页设计者需要了解的_网页字体大小数据参考
div+css与xhtml+css分别是什么意思?
xhtml+css网页制作中常见问题解决方法
表格标签table深入了解
DIV+CSS网页另类上下布局的实例代码
CSS实现每行新闻数量不等效果代码
JAVASCRIPT IE 与 FF 中兼容写法记录
让超出DIV宽度范围的文字自动显示省略号...
CSS使用学习总结
解决IE6 3像素Bug的css写法
用CSS控制表格或单元格强制换行,防止表格被英文单词或中文撑大
firefox margin-top失效的原因与解决办法
IE hack条件写法
css pointer控制在firefox下显示手型的代码
纯CSS实现上下左右都居中的代码
在DW中CSS编码需要注意和掌握的一些技巧
DIV CSS网页布局 最小高度(min-height)的妙用

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


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