I'm trying to wrap my brain around some of the finer points of CSS and I found this portion of this excerpt from the W3 CSS Visual Formatting Spec 9.2.2 particularly obtuse:
Inline-level boxes that are not inline boxes (such as replaced inline-level elements, inline-block elements, and inline-table elements) are called atomic inline-level boxes because they participate in their inline formatting context as a single opaque box.
What exactly do they mean by single opaque box?
Any clarification is much appreciated. Thanks!
The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.
You can set a block-level element to display like an inline element by setting the display property to inline. You can also cause inline elements to behave like block-level elements using the display property.
When it comes to margins and padding, browsers treat inline elements differently. You can add space to the left and right on an inline element, but you cannot add height to the top or bottom padding or margin of an inline element.
The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS. Inline elements flow left to right, meaning inline elements appear on the same line unless the line wraps or there's an explicit line break ( <br/> )
It means that the box is a singular, solid unit, and that it cannot be split across lines like an inline box can when its text cannot all fit on a single line. See section 9.4.2 which describes this splitting behavior and the terms "inline formatting context" and "line box".
If there is no longer any space on a line to fit an atomic inline box, the entire box wraps to the next line if there is a line break opportunity (otherwise it overflows the line box), even if the atomic inline box contains inline content that would partially fit the remaining space on the current line. This is because the inline content of an atomic inline doesn't participate in the same inline formatting context as the atomic inline itself — it participates in a separate inline formatting context within the atomic inline box, and therefore must remain within the boundaries of the atomic inline box.
Compare:
p {
width: 5em;
background-color: #f0f0f0;
}
span {
background-color: #d0d0d0;
}
.inline-block {
display: inline-block;
width: 4.5em;
}
<p>text <span class=inline>inline text</span> more text
<p>text <span class=inline-block>inline block</span> more text
To understand this concept you need some additional context from the same spec point you linked to, namely:
An inline box is one that is both inline-level and whose contents participate in its containing inline formatting context.
After which your quote follows.
What this means is that an inline box will render its contents as inline as well, for example, see the following:
sample <span>placeholder text</span> here
As you can see, all the elements are rendered inline, simplified that means on the same line when possible.
Now what are atomic inline boxes and what does your quote mean?
First, let's look at the following example:
.at {
display: inline-block;
}
sample <div class="at"><div>placeholder</div><div>text</div></div>here
The atomic box in this case is the divider with class at
. It participates in rendering as an inline element, but its children can be positioned in any manner separate from inline positioning. It's a single opaque box regarding inline rendering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With