Skip to content

[css-grid] Implied Minimum Size of Grid Items #283

Closed

Description

@mrego

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.

Test Chromium Firefox
css-grid-1/grid-items/grid-minimum-size-grid-items-001.xht 👍 ❌
css-grid-1/grid-items/grid-minimum-size-grid-items-002.xht 👍 ❌
css-grid-1/grid-items/grid-minimum-size-grid-items-003.xht 👍 👍
css-grid-1/grid-items/grid-minimum-size-grid-items-004.xht 👍 👍
css-grid-1/grid-items/grid-minimum-size-grid-items-005.xht 👍 ❌
css-grid-1/grid-items/grid-minimum-size-grid-items-006.xht ❌ ❌
css-grid-1/grid-items/grid-minimum-size-grid-items-007.xht 👍 ❌
css-grid-1/grid-items/grid-minimum-size-grid-items-008.xht 👍 👍
css-grid-1/grid-items/grid-minimum-size-grid-items-009.xht ❌ ❌

The status on Chormium and Firefox right now is not really important, as I'm not 100% sure if the tests are right. Thanks! 😉

Activity

  1. fantasai commented on Jul 13, 2016

    @fantasai
    Collaborator

    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?

  2. mrego commented on Jul 14, 2016

    @mrego
    MemberAuthor

    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).
    However it's true that Flexbox only do that in one axis (quick example comparing flexbox and grid).

  3. fantasai commented on Jul 14, 2016

    @fantasai
    Collaborator

    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 min-width/height: auto behavior was added in part for handling auto-minimum-sized tracks--to make their content-based minimum more configurable. We could, as an alternative to having it always apply, only apply the automatic minimum on items in such tracks.

  4. fantasai commented on Jul 18, 2016

    @fantasai
    Collaborator

    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.

  5. mrego commented on Jul 18, 2016

    @mrego
    MemberAuthor

    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 min-size: auto; only in 1 axis and Grid where it applies in both axis.

    min-size: auto applying in 1 (flexbox) or both axis (grid)

    About your comment:

    The min-width/height: auto behavior was added in part for handling auto-minimum-sized tracks--to make their content-based minimum more configurable.

    I'm not sure if I'm getting it or not. Do you mean that when you use min-content for a track size, it doesn't use the min-size but it uses the content; and if you use auto for the track size, it checks the min-size and uses it (and when min-size is auto the behavior is equivalent to min-content)?

  6. fantasai commented on Jul 18, 2016

    @fantasai
    Collaborator

    Yes, that's exactly what I meant. That is the reason we changed 'auto' to be something distinct from minmax(min-content, max-content).

  7. fantasai commented on Jul 18, 2016

    @fantasai
    Collaborator

    Proposed wording (append to first paragraph of Implied Minimum Size of Grid Items):

    If the grid item is placed in a grid track with a fixed maximum sizing function
    (and does not otherwise span a track with a non-fixed maximum 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 track (flooring at zero).

  8. mrego commented on Jul 18, 2016

    @mrego
    MemberAuthor

    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.

    I always thought that the idea of min-size: auto was to avoid shrink-to-fit by default.
    At least in Flexbox it avoids that the item shrink-to-fit in the flex container, when the flex container has a fixed width (like in the previous example). Maybe there were other reasons to add it in Flexbox that I'm missing.
    Are we sure we want something different in Grid Layout? So the items will shrink-to-fit in their grid area.

  9. 45 remaining items

  10. mrego commented on Feb 15, 2017

    @mrego
    MemberAuthor

    Thanks for resolving this issue, we've been working on adding tests for this feature to the csswg-test repository (18 tests total):

    It'd be nice if you could take a look to them and verify that they're right or not.

  11. mrego commented on Nov 20, 2017

    @mrego
    MemberAuthor

    D) With minmax(auto, 0px) or minmax(auto, 500px) (it doesn't matter the number of pixels we set as maximum) the size of the item and the track will be 250px too.

    I believe this comment is wrong, and thus the following test is wrong too http://w3c-test.org/css/css-grid/grid-items/grid-minimum-size-grid-items-017.html
    At least Firefox and Edge show a red rectangle there (in the current version as of 20th Nov 2017). Both Blink and WebKit show a green one, because I implemented both wrong following the assumption that the previous comment is right.

    Basically this is wrong because the automatic minimum size has to be clamped as the max track sizing function is fixed. So in the case of minmax(auto, 0px) the automatic minimum size of the item gets clamped to 0px instead of 250px.

    The Chromium bug is reported and will be fixed in the coming days: https://bugs.chromium.org/p/chromium/issues/detail?id=786971

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions