CSS absolute positioning positions a generated box with respect to its CSS containing block, removing it from the ordinary flow that places its siblings. The declaration
position: absolute selects this positioning scheme; offsets and size rules then determine its geometry. Its siblings do not reserve the space that it would otherwise have occupied.[ref]Visual formatting model in CSS 2.2 by W3C. §9.6, Absolute positioning
A simple example uses a positioned block ancestor with content width CSS pixels, twenty-pixel padding on both sides and content-box sizing. In the ordinary CSS2.2 case, this ancestor's padding edges establish a -pixel-wide CSS containing block for an absolutely positioned descendant, provided no nearer qualifying ancestor intervenes.[ref]
Visual formatting model details in CSS 2.2 by W3C. §10.1, absolutely positioned containing blocks
Give the descendant
left: 10px; right: 20px; width: auto, with zero horizontal margins, padding and borders. The horizontal constraint becomesso its used content width is pixels. Alternatively, width: 50%; left: 10px; right: auto gives a width of pixels under the same assumptions. Offsets and percentages therefore refer to the selected containing geometry, not automatically to the ancestor's content width.[ref]Visual formatting model details in CSS 2.2 by W3C. §10.3.7, absolute non-replaced width equation and auto cases
Absolute positioning does not remove the DOM element from the DOM tree; it changes layout participation. It can allow boxes to overlap, but does not by itself specify clipping, permanent attachment to a screen position or every painting-order relationship. Use CSS overflow and the applicable positioning rules when diagnosing those separate effects.
Articles by others on the same topic
There are currently no matching articles.