Reference: CSS 2.2 Visual formatting model details - Definition of "containing block"
Many properties in CSS are calculated according to a box's containing block. How to calculate this block is described here.
The initial containing block has the position and size of the viewport. The root element's containing block is the initial containing block.
For elements with a position
of static
, relative
or sticky
the
containing block is formed by the nearest ancestor which either:
For elements with a position
of fixed
the containing block is the initial containing block:
For elements with a position
of absolute
, the containing block is formed by the nearest
ancestor that has a position of absolute
, relative
or fixed
. There are two
situations:
b
is ignored and a
is the containing block.
Also notice how the containing block is the padding area.