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

CSS样式表
CSS比表格更难吗?
CSS2盒模型的3D示意图
CSS基本布局16例
学习CSS的10大理由
css布局中的居中问题
表格对决CSS--一场生死之战
常用CSS缩写语法总结
CSS的十八般技巧
如何用DIV+CSS制作横向菜单?
捷足先登学用CSS:HTML结构化
用CSS定义标题的几个实例
CSS中的滑动门技术
采用DIV+CSS布局的好处
Web标准:结构,表现和行为分离
CSS网站布局技巧几则总结
CSS大师Eric采访实录
CSS网页布局中ID与class的理解
CSS教程:建议font-size使用em
语义化H1标签
WEB标准教程:功能相似的标签的用法

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


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