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

CSS样式表
面向对象的CSS应用
css 文字按钮实现样式submit按钮以文本的形式显示出来
CSS 选择符的用法和实例
CSS a:hover伪类在IE6下的问题
IE6下CSS定义DIV高度的问题
CSS网页实例 利用box-sizing实现div仿框架结构实现代码
CSS样式表与HTML网页的关系分析
设计稿进行页面制作的流程和注意事项
CSS压缩的技巧与工具
CSS @font-face属性实现在网页中嵌入任意字体
通过css样式控制单元格文本超长省略
运用比较纯的CSS打造很Web2.0的按钮
CSS expression 隔行换色效果
CSS 制作有弹性的日历表
CSS Cookbook创建水平导航菜单
CSS Cookbook 创建文字导航菜单和翻转特效
区别div和span、relative和absolute、display和visibility
让页脚紧贴页面底部的CSS代码
Firefox下div层被Flash遮住的解决方法
ins标签什么时候使用

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


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