[css-grid] Implied Minimum Size of Grid Items #283
|
So... as I was editing this to clarify that it applies to both axes (as you mention), I realized that the reason it applies to one axis and not the other in Flexbox is because of the flexibility of the items. I'm wondering if that's something we need to take into account here? |
|
I don't know what's the goal in Grid Layout, but it's supposed that both directions on the grid are symmetric (at least in most situations if not all). |
|
I think one of the goals is "do the most expected thing, given Flexbox and author expectations", and of course "be symmetric across axes". The |
|
Thinking about this some more, at the very least, the grid's maximum track-sizing function should clamp the implied minimum the same way a specified size on the item would. I'm pretty sure that's what authors would expect. |
|
About author expectations I don't really know what they would be expecting in this situation. Just to make it clear, I'm attaching an example of a 20px x 20px Flexbox and Grid to show the difference between both. Flexbox applies About your comment:
I'm not sure if I'm getting it or not. Do you mean that when you use |
|
Yes, that's exactly what I meant. That is the reason we changed 'auto' to be something distinct from minmax(min-content, max-content). |
|
Proposed wording (append to first paragraph of Implied Minimum Size of Grid Items):
|
I always thought that the idea of |
|
Hm, I think “shrink-to-fit” as it's traditionally used is not what you meant. :) But yes, the purpose of The track sizing functions are at a sort of intermediary phase between the grid container and the grid item; the flex layout analogy would be flex lines, which don't have any sizing associated with them. Explicitly specifying a fixed size on the tracks is in some way similar to specifying that size on the grid container and in some ways similar to specifying that size on the grid item. But for the purpose of safety -- the reason we have (I don't know if that made much sense as an explanation. I'll try again if it didn't.) |
|
In
I think the first part is a little awkward. Maybe
|
|
|
Mmmm, I'm still not convinced about this. Probably, we should ask for authors feedback on the topic. Note that the example when you have a fixed track size was discussed before on |
|
I... am having a hard time following that thread. There seems to be vast amounts of confusion over z-index, some additional arguments over TR vs ED, and then some discussion about
The first statement is true: whatever width The second clause “The 10px column merely provides the containing block width” is also true. Then we have “and layout then ends up making it min-content” ... at that point the spec put min-content minimums on all auto-sized tracks, but this track is not auto-sized. And there was no implied minimum size on items themselves; Agree it would be good to have author feedback; my feeling though is that fixed track sizes are thought of similarly to fixed sizes on the item itself, and it's good for the automatic minimum to not overrule that. (Auto minimums are supposed to be minimally invasive. ;) The interesting question then becomes, what does |
|
Nevermind, found it in https://www.w3.org/TR/css-grid-1/#grid-items That section needs more subheadings, I think. >_< |
|
Filed #394 on sizing grid items. There's still some spec issues there afaict. |
|
Ok, I went over this issue with the Microsoft folks, and my conclusion is that we need to make sure grid items are sized the same (in both axes) as flex items are in the cross axis. See #394 for further discussion. Concretely, this means applying the CSS2.1 non-replaced block width formula to items when they are stretched, and fit-content sizing for other alignment values, and it means that the implied minimum can't take effect on fixed tracks. Note that on auto-sized tracks, whether the implied minimum is used solely for track sizing or also for sizing the item itself is indistinguishable. Additionally, the major consideration for adding implied minimum sizes to the main axis of flex items was for the viewer's benefit when the screen was made too small. Flex items do not shrink past their minimum main size--but importantly, they also do not overlap each other within a line, because their positions are determined by previous content, not by the position/size of their container (the line). Grid items, if they were floored at their content-size, do not shift in such a manner, and they would overlap each other within the row/column. Forcing a minimum on the item doesn't really help the user so much in this case. |
|
Let's see if I'm understanding the last comment. Coming back to one of the examples discussed, a grid with a fixed track of 20x20: <div style="display: grid; grid: 20px / 20px; width: 20px; height: 20px; border: thick solid; font: 50px/1 Monospace;">
<div style="background: magenta;">item</div>
</div>It seems to me that the behavior we're looking for is that the item is sized to 20x20, and the rest of the text overflows. So it could be something like in the following picture: And that's the default behavior as However, if If I'm getting it right then we might need to update the spec in a few places:
|
Yes, exactly.
The implied minimum doesn't take effect in the cross axis at all for flex items. This is because flex lines are always auto-sized anyway. (Except for single-line flex containers... but in that case the items would overflow the flex container in more or less the same way.)
Definitely applies for |
Mmmm, but in a previous comment #283 (comment) you said:
So using a flexbox as example: <div style="display: flex; width: 20px; height: 20px; border: thick solid; font: 50px/1 Monospace;">
<div style="background: magenta;">item</div>
</div>
In the previous comment you confimred that the behavior for grids in the similar example should be a 20x20 item. That's why I was understanding it was behaving the same than in the cross axis of flexboxes. Also note than if in the flexbox we use So probably I'm missing something but I'm not understanding the whole thing yet, sorry. |
|
OK, here's the current state of the text:
Let me know if this is clear, or if there's something confusing, what's confusing? :) |
@fantasai -- So, what are the use cases where implied minimums do help the user? If you have fixed tracks, per the current spec the min size is ~ignored. If you have auto-sized tracks, the items are already content sized. Does grid need an implied minimum size? |
|
It seems we should clarify this issue ASAP. CSS Grid Layout is going to be shipped in both Firefox and Chromium and we've different implementations for this: https://bugs.chromium.org/p/chromium/issues/detail?id=666940 |
|
I definitely don't think we should make the grid container's |
|
As an author I don't have a strong preference on this, other than I'd like everyone to do the same thing. Thinking it through I would lean slightly towards what Mats is saying, it seems clearer that the grid area is what affects the clamping, rather than the container. |
|
Just to wrap-up, as this issue has a lot of comments, I believe we have to agree on 2 things here: 1) The different behavior between
|
|
I agree with the conclusions in this thread, and they seem to reflect my understanding of how Grid should work. If it's not clear in the spec, I will clarify it. |
|
I don't think it's appropriate to compare Grid layout with Flexbox |
|
@mrego , I think you're conflating two separate concepts -
This applies universally, not just when stretching the items. The second issue is about whether
(of course, the grid area clamping rule trumps this when it applies) I believe the "Implied Minimum Size" in Grid is a "constraint imposed by So, I believe the rendering in Firefox for these examples are correct Regarding the clamping rule in CSS Grid: Regarding the definition of CC @jetvillegas |
|
Here's a better testcase that illustrates the different clamping/stretching cases: |
|
To follow up on what Mats is saying (though I'm not 100% sure if the concepts are all connected up correctly), I do think that the stretching effectively overrides the automatic minimum. If the track is auto-sized, then stretching would not decrease below the automatic minimum. If the track is not auto-sized, then the automatic minimum is clamped to the size of the grid area; and that clamping should be limiting any transferred size affecting the other axis as well. Let me know if that made sense or if I should try logicking again when it's not 3am. :) |
|
@MatsPalmgren I'm sorry but I don't understand the results from Firefox on the 2) case in your example, why one axis is different than the other? |
|
Regarding the difference between
@fantasai what do you think should be the expected behavior for 1) in my previous comment? |
|
And now thinking again about 2) from my previous comment. <div style="display: inline-grid; width: 40px; height: 40px; grid: minmax(0px, auto) / minmax(0px, auto); border: thick solid; font: 100px/1 Monospace;">
<div style="background: magenta;">item</div>
</div>A) If instead of B) So, if we use C) However if the track is only This is related to the step of the alogrithm in which we maximize the track sizes, as the free space would be only the 40px of the grid container. Note that in these examples Firefox and Chromium have the same behavior for A) and C) but not for B). |
|
“However, if the grid item spans only grid tracks that have a fixed max track sizing function, its automatic minimum size in that dimension is further clamped to less than or equal to the size necessary to fit its margin box within the resulting grid area (flooring at zero).” Note the use of “max” here. It means that the |
OK, fair enough -- I think you are saying that it's desirable if it does that. However, I think your statement is a bit too general - it's only the min-content size part of the automatic minimum size it should override. If we should shrink below a "transferred size" can be discussed, but let's resolve that bit in #767 So, here's what I propose to resolve this issue: Firefox changes its stretching to shrink items below their min-content size. Then I think we would have identical layout for these tests. I think that requires minimal spec changes: no Grid spec changes at all. A minor amendment to CSS Align to say that stretching may shrink the alignment subject so that its content size is below its min-content size (still not below any non- How does that sound? |
|
I think my statement was indeed too general, and is only correct in the case of an auto-sized or fixed-size track. It's not true in flex-sized tracks, or those with a minmax() function and insufficient grid container space to reach the max. I don't think we should have stretching override the minimum specified by Currently the spec modifies the automatic minimum to accommodate fixed track sizes. It does this by reducing the automatic minimum size--regardless of the item's sizing or alignment properties--to fit within the fixed limits of the grid area. It might be nice to do this for e.g. flex tracks as well, but I fear this will complicate the sizing algorithm, as the result of flexing already depends on content sizes. I'm open to suggestions on how to make the automatic minimum as helpful and unsurprising as possible, but I also don't want to come up with some weird loopback algorithm in our attempt to do so! |
Yes sorry I was thinking about the track sizes on that moment. I was mixing things. :-( Coming back to the example: <div style="display: inline-grid; width: 40px; height: 40px; grid: minmax(0px, auto) / minmax(0px, auto); border: thick solid; font: 100px/1 Monospace;">
<div style="background: magenta;">item</div>
</div>A) With |
|
Ok, so Tab and I reviewed this issue and decided to re-evaluate from first principles. Goals:
Notes on premises:
Proposed changes:
Notes on proposal:
Let us know if that seems to make sense. Thanks~ |
|
It makes sense to me and it seems it matches current Chromium behavior. I guess that the track sizes for the example are also A) 40px, B) 40px and C) 250px. And if we add one more case to the example: |












As we're approaching the CR stage I was checking again the "Implied Minimum Size of Grid Items" section of the spec.
It's kind of weird that the spec points now again to the text in Flexbox. It was like that originally then it had its own Grid text and now it points again to Flexbox. The problem I found with this is that I'm not 100% sure about some stuff, e.g. the Flexbox spec talks about main-axis, I'm assuming it applies in both axis on grid items. Also when I try to compare with Flexbox, I usually forget about
flex-shrink: 1;which is the default in Flebox and creates different results that what I see on Grid.After trying to understand it properly I was reviewing the W3C tests I created some time ago and updated them. It'd be really nice if someone could verify that my tests are right as some fail on Chromium and another on Firefox.
Please @fantasai and/or @tabatkins could you review the tests (they're just 9 simple tests where the expected result is just a 100x100 green box). Probably @MatsPalmgren would be interested in taking a look too.
css-grid-1/grid-items/grid-minimum-size-grid-items-001.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-002.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-003.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-004.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-005.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-006.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-007.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-008.xhtcss-grid-1/grid-items/grid-minimum-size-grid-items-009.xhtThe status on Chormium and Firefox right now is not really important, as I'm not 100% sure if the tests are right. Thanks!😉