关于IE7 z-index的浏览器兼容性问题完美解决方案
建站知识 2021-07-03 08:15www.168986.cn长沙网站建设
浏览器兼容性问题太让人蛋疼了,今天可是废在了IE7的z-index问题上。可又不能因为浏览器版本低而不去解决,毕竟要从用户的角度着想。百度了好多还是无法解决,google了一下,找到了方法。
直接上例子
<div id="container">
<div id="box1">This box should be on </div>
</div>
<div id="box2">
This box should not be on ;
IE however seems to create a new stacking context for positioned elements,
even when the puted z-index of that element is 'auto'.
</div>
body { margin: 0; padding: 0; }
#container { position: relative;}
#box1 { position: absolute; : 100px; left: 510px; width: 200px; height: 200px; background-color: yellow;z-index:20; }
#box2 { position: absolute; : 50px; left: 460px; width: 200px; height: 200px; background-color: lime; z-index: 10;}
这是为什么呢?其实这是IE浏览器的一个BUG——在IE浏览器中,定位元素会产生一个新的stacking context,并且从z-index的值为0开始。所以我们需要在这个元素的父元素上设置一个更高的z-index值。
在上述的box1中的父元素container设置一个更大的z-index就能解决这个问题。
body { margin: 0; padding: 0; }
#container { position: relative; z-index:30;}
#box1 { position: absolute; : 100px; left: 510px; width: 200px; height: 200px; background-color: yellow; }
//box1有没有z-index都无所谓了,但必须同position(relative或absolute)使用,就跟一个人
//生不了孩子一样,需要配合。
#box2 { position: absolute; : 50px; left: 460px; width: 200px; height: 200px; background-color: lime; z-index: 20; }
要想覆盖住父级的同级 ,父级的z-index就必须别的大,这就跟拼老爸一样,老爸强你就强,这就是传说中的哲学啊。
直接上例子
复制代码
代码如下:<div id="container">
<div id="box1">This box should be on </div>
</div>
<div id="box2">
This box should not be on ;
IE however seems to create a new stacking context for positioned elements,
even when the puted z-index of that element is 'auto'.
</div>
复制代码
代码如下:body { margin: 0; padding: 0; }
#container { position: relative;}
#box1 { position: absolute; : 100px; left: 510px; width: 200px; height: 200px; background-color: yellow;z-index:20; }
#box2 { position: absolute; : 50px; left: 460px; width: 200px; height: 200px; background-color: lime; z-index: 10;}
这是为什么呢?其实这是IE浏览器的一个BUG——在IE浏览器中,定位元素会产生一个新的stacking context,并且从z-index的值为0开始。所以我们需要在这个元素的父元素上设置一个更高的z-index值。
在上述的box1中的父元素container设置一个更大的z-index就能解决这个问题。
复制代码
代码如下:body { margin: 0; padding: 0; }
#container { position: relative; z-index:30;}
#box1 { position: absolute; : 100px; left: 510px; width: 200px; height: 200px; background-color: yellow; }
//box1有没有z-index都无所谓了,但必须同position(relative或absolute)使用,就跟一个人
//生不了孩子一样,需要配合。
#box2 { position: absolute; : 50px; left: 460px; width: 200px; height: 200px; background-color: lime; z-index: 20; }
要想覆盖住父级的同级 ,父级的z-index就必须别的大,这就跟拼老爸一样,老爸强你就强,这就是传说中的哲学啊。
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键