精美而实用的网站,关注web编程技术、网站运营、SEO推广,让您轻松愉快的学习

IE6浏览器中如果参照物没有触发haslayout,那么在ie6中“绝对定位的容器”的left和bottom就会有问题,在“相对定位的父容器”上加入 zoom:1 来触发ie的haslayout即可解决。

效果描述:灰色为“相对定位的父容器”的padding,红色为“相对定位的父容器”的内容区,绿色为“绝对定位的子容器”

问题:如果参照物没有触发haslayout,那么在ie6中“绝对定位的容器”的left和bottom就会有问题

解决方案:在“相对定位的父容器”上加入 zoom:1 来触发ie的haslayout即可解决

小技巧:通常我们在设置一个容器为position:relative的时候,都会加上zoom:1来解决很多ie下的问题

<h2>bug</h2>
<div class="m-demo">
    <div class="content"></div>
    <div class="absolute"></div>
</div>
<h2>fix</h2>
<div class="m-demo m-demo-fix">
    <div class="content"></div>
    <div class="absolute"></div>  
</div>

CSS解决代码

/* IE6中定位位置错误 */
.m-demo{position:relative;margin:0 0 10px;padding:20px;background:#ddd;color:#fff;font-size:12px;}
.m-demo .content{width:100%;height:20px;background:#ff0097;word-wrap:break-word;}
.m-demo .absolute{position:absolute;bottom:0;left:0;width:50px;height:50px;background:#4eb3b9;word-wrap:break-word;}
.m-demo-fix{zoom:1;}
Tags:IE6 绝对定位