What is the exact containing block of an absolutely positioned element if the containing block is inline?
<style type="text/css"> body > div { display: inline; position: relative; } body > div > div { position: absolute; } </style> <div> <div></div> </div> What is the exact containing block of the inner div?
In the case where the ancestor is an inline element, the containing block is a bounding box around the fill fields of the first and last inline fields generated for this element. In CSS 2.1, if an inline element is split into multiple lines containing an undefined block.
What does the "bounding box around the fill fields of the first and last inline fields generated for this element" mean in the text above?
An inline element cannot βcontainβ a block level in the traditional sense. It happens that this inline element breaks up into separate inline fields that live in anonymous block blocks surrounding this block level. See section 9.2.1.1 for the first example:
When an inline box contains a block level block in a stream, an inline block (and its inline ancestors in the same row field) splits around a block level block (and all block level bracelets that are sequential or separated only by resettable spaces and / or elements outside flow), breaking the built-in block into two fields (even if both sides are empty), one on each side of the block (s) of the level block. The row boxes before the break and after the break are enclosed in anonymous block blocks, and the block level block becomes the native of these anonymous boxes. When such an inline field affects relative positioning, any resulting translation also affects the block level contained in the inline field.
(There is no translation, so the last sentence is implacable.)
However, your case is a little more specific, as the only thing that exists between the start tag of the outer div and the start tag of the inner div and the end tag of the inner div and the end tag of the outer div, (including line breaks and indentation), which under normal circumstances gets . Thus, the built-in fields that are generated make up
- empty and
- in the same position: the same position as strut .
And since the inline element is indented, the fill fields of empty inline boxes are measured to be zero in length than the row height. (Note that some browser developer tools may display this as a single dot marked with a crosshair when you check the outer div.) The containing block of the inner (absolutely positioned) div is determined by the perimeter of these padding fields combined, and any offset on the inner div ( upper, right, lower, left) belong to this perimeter. Note, however, that since inline fields do not actually contain content, the actual position of the inner div is the same as the outer div if the outer div has content.