Behavior of Absolutely Positioned Elements Without Positioned Ancestors
An element with position: absolute is positioned relative to its nearest positioned ancestor. If none of its ancestors have a position value other than static, the element is positioned relative to the initial containing block, which is typically the <html> element (or the viewport in most cases).
The element is removed from the normal document flow; it does not affect the layout of sibling elements.
Offsets (top, right, bottom, left) are calculated relative to the viewport or initial containing block.
The element may overlap other content since it is taken out of the flow.
Creating a positioned ancestor (e.g., position: relative) allows precise placement within that ancestor instead of the viewport.
To control the placement of an absolute element within a specific container, always give the container a position value of relative, absolute, or sticky. This creates a containing block for the absolute element.
Use a positioned ancestor to limit the scope of absolute positioning.
Be mindful that absolute elements without a positioned parent will be relative to the viewport, which can affect layout on different screen sizes.
Combine absolute positioning with z-index for layered layouts.
Use for tooltips, modals, and overlays where relative positioning to a container is needed.