h2o h2o - 1 year ago 61
CSS Question

What's the difference between a block-level box and a principal block-level box?

To cite the spec:

Block-level boxes are boxes that participate in a block formatting
context. Each block-level element generates a principal block-level
box that contains descendant boxes and generated content and is also
the box involved in any positioning scheme. Some block-level elements
may generate additional boxes in addition to the principal box:
'list-item' elements. These additional boxes are placed with respect
to the principal box.

Are they essentially the same thing?

Answer Source

A principal block-level box is the block-level box generated by a given element that's directly affected by style rules that apply to the element.

Most elements generate only one box. For these elements, they are essentially the same thing, since there are no other boxes involved.

However, an element can generate more than one box depending on its display type, such as a list item; when you declare styles for such an element, the styles are typically applied to the principal box and any additional boxes that are generated will be rendered accordingly.

For example, a list item has a marker box in addition to the principal box; if you specify list-style-position: outside, the list marker will be placed outside the boundaries of the principal box but the background and borders of the principal box won't be affected. Note that the marker box is still a descendant of the principal box, so inheritable properties such as color will apply to the marker (this is why color: red turns both the text and its bullet marker red).

Most other block-level elements, including display: block but excluding display: table (see section 17.4), will simply generate a principal block box for their content and nothing else, making them essentially just "block boxes", but only for those elements.

In other words, all principal block-level boxes are block-level boxes, but not all block-level boxes are principal, for example anonymous block boxes. Also, inline elements, including inline blocks, do not generate any principal boxes themselves, nor is there such a thing as a principal inline box.