css中position:relative和overflow:hidden之间的问题
(编辑:jimmy 日期: 2025/2/26 浏览:3 次 )
今天在做网页的时候发现一个问题,在父标签中使用了overflow:hidden;时,如果子标签中有元素的position设置成relative的时候,在IE6和IE7中父元素的overflow对其将不起作用,在IE8、FF,Chrome中均正常显示如下代码:
复制代码代码如下:
<div style="height:100px; width:100px; background:#CCC; overflow:hidden;">
<div style="height:300px; width:90px; background:#999; position:relative;"></div>
</div>
效果如下图:
解决方案:将父标签的position也设置成relative,代码如下:
复制代码代码如下:
<div style="height:100px; width:100px; background:#CCC; overflow:hidden; position:relative;">
<div style="height:300px; width:90px; background:#999; position:relative;"></div>
</div>
效果如图所示:
效果如上图正常显示。
复制代码代码如下:
<div style="height:100px; width:100px; background:#CCC; overflow:hidden;">
<div style="height:300px; width:90px; background:#999; position:relative;"></div>
</div>
效果如下图:

解决方案:将父标签的position也设置成relative,代码如下:
复制代码代码如下:
<div style="height:100px; width:100px; background:#CCC; overflow:hidden; position:relative;">
<div style="height:300px; width:90px; background:#999; position:relative;"></div>
</div>
效果如图所示:

效果如上图正常显示。
下一篇:CSS之Position全面认识