如果孩子position:absolute
,父是overflow:hidden
,并且父是position:static
,孩子还是溢出:如果孩子的位置:绝对,父母是溢出:隐藏,为什么孩子溢出?
<div style="overflow:hidden;height:100px;border:2px solid red;">
<div style="position:absolute;height:200px;width:200px;background:blue;opacity:0.5">
</div>
</div>
如果父比static
以外的位置,孩子没有再溢出:
<div style="overflow:hidden;height:100px;border:2px solid red;position:relative;">
<div style="position:absolute;height:200px;width:200px;background:blue;opacity:0.5">
</div>
</div>
为什么会发生这种情况?这种行为称为什么?
我使用Chrome浏览器时,这种行为是否一致?
它与浏览器是一致的,如果是绝对的,一个元素将会寻找最接近的父元素(绝对或相对),并将它用作参考来绘制它自己,如果没有找到它,它将使用该窗口作为参考,会出现在前面的静态元素 –