-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-flexbox][css-grid] Unifying grid-auto-flow and flex-flow #11480
Comments
I wanted to comment on one piece of this. The rest looks like a great direction to explore, but I'm not enough of a CSS expert to opine that it's definitely the way to go. Giving a Fundamentally, these say whether to stack items in the |
It's great that we're starting to think about solutions to the TAG recommendation for unified layout properties. I think this is a good proposal. And I agree Do you see this as part of a family of other For example, I wonder if maybe the syntax for However, I'm thinking about how there are still lots of essential properties needed for each layout system that are unique to each layout system. For example, to create a flex or grid layout, I'm still most likely going to use If I mixed them together in the same layout, I'd probably write something like this: .my-layout {
display: flex;
item-flow: row-reverse wrap;
> * {
flex: 1;
}
@media (width > 20rem) {
display: grid;
grid-template-columns: repeat(auto-fill, 8rem);
}
} In the above example, using |
(tldr: complaints up top, counter-proposal near the bottom) I don't think this proposal works. If we were just talking about Flexbox and Grid, this seems pretty reasonable, to the point that I'd likely have supported it if was suggested a few years ago. But in trying to wedge Masonry into the same framework of property and value names, it makes some pretty serious mistakes. In both Flexbox and Grid, the Also, the So far, so good: these two layout modes (Flexbox, and Grid auto-layout) have very similar concepts, used in very similar ways, and the same sorts of terms apply meaningfully across both. There's some tension - These arguments don't apply to Masonry. @jyasskin brings up the first issue: this proposal defines that Second, the Third, the entire concept of wrapping doesn't apply to Masonry. This proposal defines it as dictating in which direction Masonry fills its tracks, but this exact concept is controlled by Fourth, the additional values still don't have great meanings in Masonry:
Fifth, while I think applying the 'slack' concept to Flexbox is pretty interesting and worth pursuing †², afaict there's no meaningful definition for Grid. In conclusion, I think this proposal makes some unacceptable design decisions, which are forced on it due to trying to fit Masonry's layout concepts into the "direction + wrap" concept pair that Flexbox and auto-Grid use. I would oppose this. Instead, Masonry needs its own set of properties to handle the "direction + tie-breaking" concept pair that it actually uses, as I proposed in #11243 (comment). If we did want to define a single collective set of properties, I think it's possible! A good design just has to recognize that some concepts don't apply to some layout modes, rather than trying to cram all of them into the same set of concepts, like how different layout modes use different subsets of the
If we use Grid-masonry, we'll still need a separate way to indicate that a given Grid is using Masonry instead of Grid layout. If using †¹: What Grid does with †²: I really like that the initial value of |
I think you're misreading the proposal. Higher values are looser adherence to dense packing in the proposal (i.e. the larger the slack, the looser packing we allow). |
Ah, I'm not misreading, we're just thinking of the condition in opposite ways. My objection is partly semantic (this is using slack as a negative condition, while the other usages are a positive condition), but the more important one is practical. The point of the slack is to give you some control over the decision of whether to keep the overflowing item on the line (causing shrinkage) or push it to the next line (causing flexing). What's more important for that decision: how much of the item does fit on the line, or how much of the item doesn't fit on the line? As a practical example, say your flexbox is 1000px wide, and the line is currently 800px filled, so 200px left. The next item is one of two possible elements: either a 250px item, or a 2000px item (lots of text, guaranteed to shrink and internall wrap). What's more important for deciding whether to squeeze either item in or push it to the next line: the fact that there's 200px left on the line, or the fact that one item overflows by 50px (requiring shrinking from 1050 to 1000) and the other overflows by 1800px (requiring shrinking from 2800 to 1000)? I think it's pretty clear that it's the latter. The 200px is irrelevant for the decision, all that matters is how much shrink the item is going to force everything on the line to do if you cram it in. You're probably okay with the 50px overflow (only 5% over!), but definitely not okay with the 1800px overflow (180% over!). If you can roughly predict the size of the items, the two numbers are interchangeable: if one is So, I think this sort of "dense" behavior is better achieved by just using the proposed "normal flexbox" behavior and setting This then frees up |
Ah, here's the positive-condition version of your dense proposal (I rewrote the above comment three times, and of course didn't think of this until after I hit Comment): That said, my practical objection still stands. If you can predict item sizes, then "amount of leftover space on the line" and "amount the item overflows by" are interchangeable and we can use either; if you can't predict item sizes, then it's still more important to control how much overflow is happening than how much free space is left. And |
The TAG response to the masonry syntax issue asked us to look into unifying controls for our layout modes, calling out
grid-auto-flow
andflex-flow
(flex-direction
+flex-wrap
) in particular. Apple looked into this, and we have the following syntax proposal:Introduce
item-flow
aliased to bothflex-flow
andgrid-auto-flow
and defined as a shorthand for the following properties:item-direction
(also aliased asflex-direction
)row | column | row-reverse | column-reverse
item-wrap
(also aliased asflex-wrap
)auto | wrap | wrap-reverse | nowrap
auto
computes to eitherwrap
(for Grid) ornowrap
(for Flexbox)nowrap
in Grid would mean autoplacement adds implicit tracks instead of wrapping to the next rowitem-pack
normal | dense
dense
packing for Flexbox would mean that instead of breaking lines as soon as an item can’t fit, we try to cram in one more, triggeringflex-shrink
behavior instead offlex-grow
on that line. See [css-flexbox-2] Add flex-wrap: dense #3071.item-pack: normal | dense || [ collapse | balance ]
could allow:collapse
triggering a masonry-style layout for Grid (see [css-grid-3][masonry] Masonry Syntax Debate #11243).balance
opting into balanced line-wrapping for Flexbox ([css-flexbox-2] Add flex-wrap: balance; #3070).item-slack
<length-percentage>
masonry-slack
property. See [css-grid] Decide on a name formasonry-slack
#10884.10px
slack would mean “if there’s only 10px overflow on this line when adding the next item, cram it in anyway, as squeezing in an extra 10px is no big deal”.10px
slack would mean “if there’s only 10px empty space left on this line, don’t try to cram in the next item, that’s too much cramming”.Caveats: This would make
flex-flow
andgrid-auto-flow
cascade as a single property, which is a change in behavior and therefore could have some Web-compat impact.Variations: This is our initial sketch, but there are some variations we’ve considered:
item-slack
should be a longhand ofitem-flow
or not: it's often nice to put it in theitem-flow
shorthand, but it might also make sense for it to cascade independently.item-
prefix. Ideas we’ve come up with so far includeitem-
,box-
,items-
, andplacement-
. (We’re drawing the “item” terminology from the specs and from thealign-items
property.)Thoughts?
The text was updated successfully, but these errors were encountered: