[CSS] Containing Block

Identifying the containing block

The process for identifying the containing block depends entirely on the value of the element's position property:

  1. If the position property is staticrelative, or sticky, the containing block is formed by the edge of the content box of the nearest ancestor element that is either a block container (such as an inline-block, block, or list-item element) or establishes a formatting context (such as a table container, flex container, grid container, or the block container itself).

  2. If the position property is absolute, the containing block is formed by the edge of the padding box of the nearest ancestor element that has a position value other than static (fixedabsoluterelative, or sticky).

  3. If the position property is fixed, the containing block is established by the viewport (in the case of continuous media) or the page area (in the case of paged media).

  4. If the position property is absolute or fixed, the containing block may also be formed by the edge of the padding box of the nearest ancestor element that has any of the following:

Diagram of the box model

posted @ 2024-12-01 16:58  Zhentiw  阅读(11)  评论(0)    收藏  举报