w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.5k stars 661 forks source link

[css-flexbox][css-align] Support `justify-items` for flexbox containers (and `justify-self` for items) #9495

Open nicoburns opened 1 year ago

nicoburns commented 1 year ago

Spec links:

Motivation

Alignment with CSS Grid is wonderfully symmetrical: you can align-items in one axis and justify-items in the other and this does exactly the same thing. Sadly the same cannot be said for Flexbox: align-items works nicely, but justify-items does nothing at all! I consider this undesirable for two reasons:

Proposal

It occurs to me that could be fixed. Specifically for the case when justify-content is stretch (which is of course the default) we could enable the justify-items property to take effect.

Loirooriol commented 1 year ago

But you can use place-content: center for both axes. You will just need flex-wrap: wrap to enable align-content.

justify-items just sets the default justify-self of the children, and justify-self doesn't make sense for items that flow along a line like in flex.

yisibl commented 1 week ago

@dholbert answers the reasons behind this in detail here: https://stackoverflow.com/a/32569434/7983605

However, the css-align-3 specification says that justify-items applies to all elements, which should need clarification here?

image


I think the correct behavior would be:

justify-items Applies to: block-level boxes, absolutely-positioned boxes, and grid items