Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Spec - Atomic Inline Level Boxes

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!

like image 575
Justin Foss Avatar asked Feb 16 '15 08:02

Justin Foss


People also ask

What is inline box in CSS?

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.

How do you make a block-level element inline?

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.

Can you use padding on inline elements?

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.

Can we set height for inline elements?

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/> )


2 Answers

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
like image 69
BoltClock Avatar answered Sep 30 '22 13:09

BoltClock


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.

like image 32
Etheryte Avatar answered Sep 30 '22 12:09

Etheryte