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

CSS样式表
间距浮动与对齐的最佳方案
Web开发期待的CSS的一些功能
CSS网页设计:百分比进行背景图片定位
CSS缩写6个图例总结
五条非常重要的CSS技巧
CSS入门:XHTML文档结构树
WEB2.0的五个技术点:单手定则
完美网页应该适应不同人群
CSS教程:vertical-align的值
CSS样式表渐进增强的基本概念
css sprites把很多小图集成在一张图片上
介绍CSS3使用技巧5个
CSS3教程(2):网页边框半径和网页圆角
CSS3教程(3):border-color网页边框色彩
CSS3教程(4):网页边框和网页文字阴影
CSS3教程(5):网页背景图片
CSS3教程(6):创建网站多列
CSS3教程(7):CSS3嵌入字体
CSS3教程(8):CSS3透明度指南
CSS3教程(9):设置RGB颜色

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


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