Usually, an element positioned using position: fixed
can escape the bounds of its ancestors, even when they have overflow: hidden
set.
.container {
height: 100px;
width: 100px;
background: #fcc;
overflow: hidden;
}
.child {
position: fixed;
left: 50px;
top: 50px;
height: 100px;
width: 100px;
background: #ccf;
}
<div class="container">
<div class="child"></div>
</div>
There seems to be one exception: When an ancestor becomes the containing block for fixed elements (by having transform
, perspective
, filter
or will-change: transform
set, see MDN under fixed
), in combination with overflow: hidden
, fixed elements cannot escape the containing block anymore:
.container {
height: 100px;
width: 100px;
background: #fcc;
overflow: hidden;
transform: translate(0, 0);
}
.child {
position: fixed;
left: 50px;
top: 50px;
height: 100px;
width: 100px;
background: #ccf;
}
<div class="container">
<div class="child"></div>
</div>
I am finding it difficult to find information about this behaviour. Is this behaviour specifically documented anywhere?
I am developing a component that will be rendered inside such a containing block, and I have no control over the CSS of the containing block. My question is: Is there any way for the child to escape its containing block, be it with position: fixed
or any other way?