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

CSS样式表
IE和Firefox浏览器CSS网页布局不同点
CSS改变选择网页文字背景色
CSS3教程(1):什么是CSS3
浏览器Apple Safari和Google Chrome内核webkit
YaHoo方法:CSS Reset重设浏览器的样式
你知道吗?CSS样式表也能挂网页木马
通过宜家的家具设计方法学习CSS模块化
可读性CSS代码编写的小技巧
建议网页开发者使用IE8测试版测试网站
帮我写出更好的CSS代码的一些技巧
CSS初学福音:解决你对英文单词的不理解
两个CSS代码精简工具(网页推荐)
IE6图片元素img下出现多余空白的问题
将设计稿转换成WEB页面职业者
W3C标准以及XHTML和HTML
网页字体该如何设置?
学CSS网页布局排查错误的方法
CSS常见的让元素水平居中显示的方法
CSS网页布局教程:CSS伪类定义3种方法
CSS模块化思想的优势

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


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