An element with absolute positioning no longer adheres to the regular document flow.
Instead, it is placed on a separate layer independent of other elements.
Rather than being positioned based on its location within the normal flow, absolute positioning specifies the distance from each side of the containing element. developer.mozilla.org/en-US/docs/Web/CSS/position
(the "containing element" is the initial containing block.)
The properties top, bottom, left, and right are used for positioning relative to the containing block.
Please explain your reasoning with code ---
/* when you apply this style to 'div', nested divs also become absolutely positioned*/
/* Absolutely positioned elements are positioned relative to their nearest positioned ancestor element.*/
/* Then each container div is positioned relative to its nearest div */
/* Comment out this div style and use the following div for solution. */
div {
width: 200px;
height: 200px;
position: absolute;
}
/* Positioned relative to the upper div */
.first-container {
background-color: #9ad0ec;
}
/* Positioned relative to the nearest ancestor with positioning (first-container) */
.second-container {
background-color: red;
left: 200px;
}
/* Positioned relative to the nearest ancestor with positioning (second-container) */
.third-container {
background-color: blue;
left: 200px;
top: 200px;
}
<body>
<div>
<div class="first-container" />
<div class="second-container" />
<div class="third-container" />
</div>
</body>
To achieve the desired output, 'top' or 'bottom' needs to be set in the container-style.
Check this sandbox