Because a container box can only contains boxes, a anonymous text (ie a text that is not enclosed in an element) will be contained in an anonymous box.
If a container box (inline or block) has a block-level box inside it, then we force it to have only block-level boxes inside it.
Anonymous block boxes are ignored when resolving percentage values that would refer to it: the closest non-anonymous ancestor box is used instead.
In the basic example, if the child of the anonymous block box inside the DIV needs to know the height of its containing block to resolve a percentage height, then it will use the height of the containing block formed by the DIV. It will not use the height of the anonymous block box.
Container box with a child block box = Anonymous Block Box
if a block container box has a block-level box inside it, then we force it to have only block-level boxes inside it.
In a document like this:
border: 1px solid DeepSkyBlue;
border: 1px solid blue;
The DIV element generates a block container box that has both:
- inline content (“Some text”) that is contained in an anonymous block box
- and block content (“More Text”)
Diagram showing the three boxes:
Inline Box text interrupted by a block = anonymous block boxes
When an inline box contains a block-level box, the inline content is broken around the block-level box splitting the inline box into two boxes, one on each side of the block-level box(es). The line boxes before the break and after the break are enclosed in anonymous block boxes.
border: 2px solid aqua;
border: 2px solid DeepSkyBlue;
This is anonymous text before the SPAN.
<SPAN>This is the content of SPAN.</SPAN>
This is anonymous text after the SPAN.
The P element contains:
- a chunk of anonymous text C1: This is anonymous text before the SPAN
- followed by a block-level element. It becomes a sibling of the anonymous boxes
- followed by another chunk of anonymous text. C2: This is anonymous text afer the SPAN
The resulting boxes would be a block container box representing the P element containing:
- an anonymous block box
- the SPAN block box,
- and another anonymous block box
Properties set on the container element still apply to the boxes and content of that element. For example, the background color apply also to the anonymous box.