I have the below html:
<body>
<div class="div1">
</div>
<div class="div2">
</div>
</body>
It has the following style sheet applied to it:
.div1{
width: 100px;
height: 100px;
background-color: orange;
position: relative;
}
.div2{
width: 100px;
height: 100px;
background-color: blue;
position: absolute;
}
My understanding from W3Schools is that an absolute positioned element is positioned relative to the nearest positioned ancestor, however if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Shouldn't div2 therefore sit on top of div1 rather than beneath it?