In response to your inquiry, I revisited Section 9.2.1 of the CSS 2.1 specification.
Upon reviewing this section, it is evident that the inline formatting context is activated when a block container box exclusively contains inline elements.
Unlike a block formatting context which can be deliberately triggered (for instance, by setting overflow: hidden
on a block-level element), an inline formatting context does not have a method for explicit initiation.
Inline formatting contexts seem to always exist within descendant block boxes inside a "principal block-level box", with these descendant block boxes possibly being anonymous.
I propose the following analogy as a way to comprehend block/inline formatting contexts.
A block-level element (such as a <div>
) serves two main purposes: positioning and content formatting.
Regarding positioning, a block-level element functions as a "block-level box".
For content formatting, a block-level element acts as a "block container box".
As a "block-level box", the block-element behaves based on the type of positioning (static, absolute, relative, fixed) indicated by the position
property.
Functioning as a "block container box", the block-element establishes a block-formatting context if it has at least one child block-level element. If all child elements are inline-level boxes, then an inline-formatting context emerges.
If the "block container box" includes text and block elements, the text is viewed as being enclosed in one or more anonymous block-level boxes, creating a block-formatting context.
Sidebar
The CSS specification can be quite dense. Despite multiple readings of Chapters 9 and 10, translating them into plain English remains a challenge.