I am struggling to grasp why a div
set as absolute
inside a relative
div
is overlapping with other elements. From what I understand, it should remain fixed within its parent relative
div
, right?
This is my solution:
#container {
position: relative;
}
#overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
background-image: url(https://picsum.photos/800);
background-size: cover;
}
<div id="before">
some div
</div>
<div id="container">
<div id="overlay">
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
<div>Some text.</div>
</div>
</div>
<div id="after">
other div
</div>
I am puzzled by the fact that #content
, placed as relative
, overlaps with #after
.