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

CSS样式表
CSS垂直居中网页布局实现的5种方法
CSS实现绝对的完美圆角框
WebKit中可用的CSS高级特性
css框架(CSS Frameworks):CSS框架应用
针对不同版本的IE浏览器的条件CSS应用
CSS代码优化7个准则
CSS实例:创建有图标的网站导航菜单
以图例方式介绍CSS制作网页详细步骤
推荐43个XHTML+CSS网页及导航布局实例教程
制作网页过程种需要学习的CSS教程
学习CSS的人值得去的6个CSS资源站
Webjx推荐20个关于CSS3优秀学习资源
import与link的具体区别
CSS设计制作网页不要使用@import
网页收集的优秀的CSS技巧与教程
CSS实例教程:弹性+固宽布局
网页CSS优化使网页具有语义化
Webjx推荐30个网站导航使用CSS的最佳方式
总结:CSS样式表的技术优势和功能
格式化CSS和精简CSS的在线CSS优化工具

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


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