The Containing Block
The containing block of a positioned element is determined as follows:
The containing block of the root element (also called the initial containing block) is established by the user agent. In HTML, the root element is the
html
element, although some browsers may usebody
.For nonroot elements, if an element’s
position
value isrelative
orstatic
, its containing block is formed by the content edge of the nearest block-level, table-, cell-, or inline-block ancestor box. (Despite this rule, relatively positioned elements are still simply offset, not positioned with respect to the containing block described here.)For nonroot elements that have a
position
value ofabsolute
, the containing block is set to the nearest ancestor (of any kind) that has aposition
value other thanstatic
. This happens as follows:If the ancestor is block-level, the containing block is that element’s padding edge; in other words, it is the area that would be bounded by a border.
If the ancestor is inline-level, the containing block is set to the content edge of the ancestor. In left-to-right languages, the top and left of the containing block are the top and left content edges of the first box in the ancestor, and the bottom and right edges are the bottom and right content edges of the last box. In right-to-left languages, the right edge of the containing block corresponds to the right content edge of the first box, and the left is taken from the last box. The top and bottom are the same.
Get CSS Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.