You know the single-value syntax: .thing { display: block; }
. The value “block” being a single value. There are lots of single values for display
. For example, inline-flex
, which is like flex
in that it becomse a flex container, but behaves like an inline-level element rather than a block-level element. Somewhat intuitive, but much better served by a two-value system that can apply that same concept more broadly and just as intuitively.
For a deep look, you should read Rachel Andrew’s blog post The two-value syntax of the CSS Display property. The spec is also a decent read, as is this video from Miriam:
This is how it maps in my brain
You essentially pick one from each column to describe the layout you want. So the existing values we use all the time map out something like this:
Another way to think about those two columns I have there is “outside” and “inside” display values. Outside, as in, how it flows with other elements around it. Inside, as in, how layout happens inside those elements.
Can you actually use it?
Not really. Firefox 70 is first out of the gate with it, and there are no other signals for support from Chrome-land or Safari-land that I know about. It’s a great evolution of CSS, but as far as day-to-day usage, it’ll be years out. Something as vital as layout isn’t something you wanna let fail just for this somewhat minor descriptive benefit. Nor is it probably worth the trouble to progressively enhance with @supports
and such.
Tidbits
- Check out the automatic transformations bit. Just because you set an element to a particular display, doesn’t mean it might not be overruled by a certain situation. I’m assuming it’s mostly talking about an element being forced to be a flex item or grid item.
- There is implied shorthand. Like if you
inline list-item
, that’s reallyinline flow list-item
whereaslist-item
isblock flow list-item
. Looks all fairly intuitive. - You still use stuff like
table-row
andtable-header-group
. Those are single-value deals, as iscontents
andnone
. - Column one technically includes
run-in
too, but as far as I know, no browser has ever supportedrun-in
display. - Column two technically includes
ruby
, but I have never understood what that even is.
How we talk about CSS
I like how Rachel ties this change to a more rational mental and teaching model:
… They properly explain the interaction of boxes with other boxes, in terms of whether they are block or inline, plus the behavior of the children. For understanding what display is and does, I think they make for a very useful clarification. As a result, I’ve started to teach display using these two values to help explain what is going on when you change formatting contexts.
It is always exciting to see new features being implemented, I hope that other browsers will also implement these two-value versions soon. And then, in the not too distant future we’ll be able to write CSS in the same way as we now explain it, clearly demonstrating the relationship between boxes and the behavior of their children.
Hi Chris,
Aha, thanks for the new perspectives. Also the CodePen’s in the cited Rachel Andrew’s blog post are very clarifying!
Aside:
“#Wierdnesses (…) as far as I know, no browser has ever supported run-in display.”
You remember your 2010-article css-tricks.com/run-in? ;-)
It says: “Firefox doesn’t support it at all, including the version 4 betas. The WebKit family (Safari and Chrome) are supporting it, as well as Opera and IE8.”
In the meantime:
– Firefox has won!
– Internet Explorer is still supporting it until the end of live (IE11), in your testpage css-tricks.com/examples/Runin all fishes are swimmin’-in with IE11; but MS-Edge has dropped the support.
– Chrome, Opera and Safari have also dropped their support; only Opera-Mini is supporting it nowadays.
– Only 1.65% global browser users can enjoy the run-in (0.19% IE8/IE10, 1.85% IE11, 1.3% Opera Mini).
– See: caniuse.com/#search=run-in.
– The w3c css-valisator is giving green to your test page, in line with the specs.
– But the Developer Panes in FF and Chrome don’t hesitate to abandon the run-in as “invalid property value”.
Conclusion: de facto we can see the display: run-in; as invalid.
Sorry, but what did lead you to this conclusion? Both the spec (the informative table right before the section 2.1) and Rachel Andrew’s article seem to clearly list this combination as perfectly valid, it means “block-level block container aka block box” and is equivalent to the good old
block
value. In other words, its a simple block box that doesn’t establish new block formatting context, so it doesn’t clear any floats and lets margins of its children collapse with its own margins), in contrast toblock flow-root
(aka justflow-root
), which makes a block box that establishes a new BFC.Ooops! I can clarify that. I was referring to this in the spec:
I take that to mean that just because you want something to behave like a block container, if it’s a flex child (or the like, I think), it is going to behave that way.
Ah yes, these “blockification” and “inlinification” things are really tricky (especially the latter). Basically, yes, they happen when we try to place something into the context where it can’t behave as its value suggests. “Blockification” of initially inline elements is more common (traditional examples are floating and absolutely positioned inline elements, converting inline elements into flex or grid items, yes, has the same effect). “Inlinification” still seems exotic thing to me (I haven’t seen it in practice yet, and looking through the specs I found it only in the Ruby context, which itself is a rather exotic thing). But basically, as far as I understand, it means that when we have to place a block container into some environment that accepts only inline children, CSS has to convert this block into an inline-block (
inline flow-root
), sinceinline flow
(akainline
) would lose any block container features.It is, but it’s a different thing, it’s just the independent formatting context rather than automatic box type transformation. It does affect the behavior, but doesn’t change any of the
display
value component.So please fix the red line on the diagram:)
Impressive!Thanks for sharing the post.