Absolute positioning is in relation to the closest positioned ancestor (parent, grandparent, etc…). So div.absolute will be positioned relative to the body, not div.container. I’m not sure what you are trying to do here but you might want to consider flexbox or grid instead if you are trying to position siblings relative to each other.
Yes. But I didn’t understand the concept of position relative and absolute. Why the div.absolute is completely relative to the body instead of div.relative (even after I’ve added the position:relative property to the div.relative)
Because that’s the way absolute positioning works. From the MDN article:
“The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to its closest positioned ancestor, if any; otherwise, it is placed relative to the initial containing block.”
div.container (the one with relative positioning) is not an ancestor of div.absolute, it is a sibling. The nearest ancestor is the body.
Adding position relative to div.container does not affect affect div.absolute.