Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

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?

like image 855
TheFooProgrammer Avatar asked Feb 27 '13 14:02

TheFooProgrammer


People also ask

What is the difference between a block level element and an inline element?

Difference Between Inline and Block Elements in HTMLInline elements only cover the space as bounded by the tags in the HTML element. Block elements have top and bottom margins. Inline elements don't have a top and bottom margin. Examples of block elements - <p>,<div>,<hr> .

What is a block level element?

A Block-level element occupies the entire horizontal space of its parent element (container), and vertical space equal to the height of its contents, thereby creating a "block". Browsers typically display the block-level element with a newline both before and after the element.

Is label inline or block?

According to the MDN pages, label elements "are simple inline elements".


1 Answers

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.

like image 141
BoltClock Avatar answered Oct 24 '22 20:10

BoltClock