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

CSS样式表
可以给img元素设置背景图
不通过JavaScript实现的自动滚动视差效果
学DIV+CSS技术,如何入门?
XHTML+CSS制作样式风格切换的WEB站点
解决IE6.0、IE5.0、IE5.5差异
DIV+CSS制作的个性水平导航菜单实例
css里expression实现界面对象的批量控制
利用CSS框架进行高效率的站点开发 Elements
CSS模块化设计:从空格谈起
在IE流览器中正确显示PNG透明图片
CSS样式表创建美妙绝伦的网站
性感的CSS菜单(Menus)
CSS教程关于css框架网页设计
以HTML为基础学习DIV+CSS
提高CSS文件可维护性的五种方法
dl、dt、dd 标记来改造163邮箱的广告条
WEB前端涉及的布局、结构化和标准化
CSS网页制作布局实例教程
CSS教程:认识层叠规则互相作用
ul结合CSS制作网页相册滑动浏览效果

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


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