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

CSS样式表
css:之三行三列等高布局图文教程
一些很不错的css技巧,但也常为人们所忽略
div+css布局必须要知道的css条件注释理论及实践
超赞的随机颜色搭配工具
应用WEB标准实例:列表页面的制作
用CSS给图片打标的方法
用css动态生成闪字的代码
用滑动门技术设计按钮的图文教程
如何实现多风格选择 样式实时切换
关于超链接的下划线 使用说明
用CSS给图片打标的代码
学习样式表CSS参考-常用的CSS知识
XHTML下用dl,dt,dd标签实现翻页的效果代码
CSS网页布局入门教程1:一列固定宽度
CSS网页布局入门教程2:一列自适应宽度
CSS网页布局入门教程3:一列固定宽度居中
CSS网页布局入门教程4:二列固定宽度
CSS网页布局入门教程8:三列浮动中间列宽度自适应
DIV+CSS 英文命名规范
发现四种在网页中使用CSS样式表的方法

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


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