Home > Article > Web Front-end > Getting started with CSS layout
The concept often used in HTML is the element, but in CSS, the basic unit of layout is the box, which is always rectangular.
There is no one-to-one correspondence between elements and boxes. One element may generate multiple boxes. Pseudo-elements in CSS rules may also generate boxes. Elements with a display attribute of none will not generate boxes.
In addition to elements, text nodes in HTML may also generate boxes.
A box includes content, border, Padding, Margin(margin). The following figure shows the intuitive meaning of the box model:
The definition of the size (width and height) of the box is affected by the box-sizing attribute. Box-sizing can choose from three modes: content-box (default), padding-box and border-box. Normal flowThe normal flow is the page, and most of the boxes are arranged in the normal flow. Boxes in the normal stream must be located in a certain formatting context. There are two formatting contexts in the normal stream: block formatting context (BFC) and inline formatting context (IFC). In block-level formatting context, boxes are arranged vertically, and in inline formatting context, boxes are arranged horizontally. The normal flow root container is a block-level formatting context. Different boxes may generate inline formatting context or block-level formatting context internally. Block level and inline levelBoxes in the normal flow are divided into block level and inline level. No inline level box can be directly put into the block level formatting context. . If an element will determine whether the box is inline level or block level:overflow is not visible.
Absolute positioning and floating block containers always create a new block-level formatting context.
Elements whose display value is table or inline-table will generate a table, and a special formatting method will be used inside the table to arrange its internal elements. Elements whose display value is grid or inline-grid will generate grid elements. Similar to the table situation, it also uses a special formatting method internally to mark its internal elements.Elements with a display value of flex or inline-flex will generate an adaptive container (flex container), and the adaptive container will generate an adaptive formatting context (flex formatting context) inside it.
The above is the detailed content of Getting started with CSS layout. For more information, please follow other related articles on the PHP Chinese website!