解决IE6,IE7不能隐藏(overflow:hidden)绝对定位溢出的内容
令人蛋疼的IE,IE6/IE7下父元素有相对/绝对定位时,子元素在IE6和IE7下overflow:hidden;失效。
情况一:(在parent上增加position:relative)
复制代码代码如下:
style type=”text/css”
.parent{ width:100px; height:100px;border:1px solid #f00; overflow:hidden; position:relative;}
.sonF{ position:relative;}
.son{ width:100px; height:100px; position:absolute; left:0;top:0;}
p{margin:0;padding:0;}
/style
/head
body
div class=”parent”
div class=”sonF”
div class=”son”
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
pbbbb/p
pbbbbb/p
/div
/div
/div
情况二:(给son增加position:relative)
复制代码代码如下:
style type=”text/css”
.parent{ width:100px; height:100px; position:absolute; border:1px solid #f00;}
.son{ width:100px; height:100px;left:0;top:0; overflow:hidden; position:relative;}
p{margin:0;padding:0;}
/style
div class=”parent”
div class=”son”
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
paaaaaaaaaaaaaa/p
/div
/div
如下图:
如果.parent中的position设置为absolute也是如此。
终上所述:
哪个需要设置overflow;hidden,生效,就在哪个上面设置position:relative;