IE7下position的z-index Bug解决方案

通常设置position后,通过z-index属性来设置div的层叠情况。

但是在IE7中,设置position后,z-index会失效。导致div的层叠出现问题。

具体效果可以看这个页面

http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html

以下分别是IE7与IE8之间的差别:


请先认真看他们的HTML和CSS信息:

正常理解是应该显示上图右边的那种情况,但是IE7上的确是一件很怪异的事情,查了许多资料终于找到了解决方案:
http://brenelz.com/blog/squish-the-internet-explorer-z-index-bug/

In Internet Explorer positioned elements generate a new stacking context, starting with a z-index value of 0. Therefore z-index doesn’t work correctly. So we giving the parent element a higher z-index actual fixes the bug

以上告诉我们,IE设置了position的元素会生成一个新的stacking context,导致 z-index 为0,所以才失效了。所以我们需要在这个元素的父元素上设置一个更高的z-index值。

在上述的box1中的父元素container设置一个更大的z-index就能解决这个问题,如下:

CSS
1
#container { position : relative ; z-index : 30 ; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值