Visitar URL original
[css-grid] minmax(auto,min-content) under a max-content constraint · Issue #3565 · w3c/csswg-drafts · GitHub
Skip to content

[css-grid] minmax(auto,min-content) under a max-content constraint #3565

Closed

Description

@Loirooriol

Consider this grid: https://jsfiddle.net/xnvrk7h8/

.grid {
  display: grid;
  grid: auto / minmax(auto, min-content);
  float: left;
  border: 3px solid;
}
.item {
  background: blue;
}
.float {
  float: left;
  width: 50px;
  height: 50px;
}
<div class="grid">
  <div class="item">
    <div class="float"></div>
    <div class="float"></div>
  </div>
</div>

float: left sizes the grid under a max-content constraint (assuming the window is wide enough).

The grid item has a max-content width of of 100px when the floats are in the same line, and a min-content of 50px when they are in different lines.

According to https://drafts.csswg.org/css-grid/#algo-single-span-items,

If the track has an auto min track sizing function and the grid container is being sized under a min/max-content constraint, set the track’s base size to the maximum of its items’ min/max-content contributions, respectively, each limited by the max track sizing function if that is fixed and ultimately floored by its minimum contribution.

The track does have an auto min track sizing function and the grid container is being sized under a max-content constraint. So the track’s base size should be set to 100px. This is not limited by min-content because it's not fixed, and the minimum contribution is less than 100px:

The minimum contribution of an item is the outer size that would result from assuming the item’s used minimum size (min-width or min-height, whichever matches the relevant axis) as its preferred size (width or height, whichever matches the relevant axis) if its computed preferred size behaves as auto, or else the item’s min-content contribution.

Here the computed width is auto, and the used value of min-width: auto is the content size suggestion, 50px.

If the track has a min-content max track sizing function, set its growth limit to the maximum of the items’ min-content contributions.

So the growth limit is initially set to 50px, but

if a track’s growth limit is now less than its base size, increase the growth limit to match the base size.

So both the base size and the growth limit should be 100px, the track is frozen, and the rest of the algorithm doesn't seem relevant.

However, this is not what implementations do:

results

Note that in Firefox the column is 50px wide but the grid container is 100px wide, so strange, @MatsPalmgren. This is solved by using min-width: 0 in the grid item, which alters the minimum contribution but shouldn't affect the result.

Is my understanding of the spec correct? Should it be changed to match implementations?

Activity

  1. fantasai commented on Jan 29, 2019

    @fantasai
    Collaborator

    I think you're right, something's not right here. Probably the automatic minimum should be limited by min-content here.

  2. fantasai commented on Jan 29, 2019

    @fantasai
    Collaborator

    OK, I think the correct edit here is to remove “if that is fixed” from the spec text you quote:

    If the track has an auto min track sizing function and the grid container is being sized under a min/max-content constraint, set the track’s base size to the maximum of its items’ min/max-content contributions, respectively, each limited by the max track sizing function if that is fixed and ultimately floored by its minimum contribution.

    What do you think?

  3. fantasai commented on Jan 29, 2019

    @fantasai
    Collaborator
  4. Loirooriol commented on Jan 29, 2019

    @Loirooriol
    ContributorAuthor

    I think the correct edit here is to remove “if that is fixed”

    I don't think the sentence makes sense without “if that is fixed”, because it's not clear how a length should be limited by something which is not a length or a resolveable percentage.

    For example, if the max track sizing function is the keyword max-content, it needs to be defined that in this case the limit is the item’s max-content contribution.

    It can also be a <flex> value, and these are not obvious because at that point fr is not known yet.

  5. fantasai commented on Jan 29, 2019

    @fantasai
    Collaborator

    So “if that is fixed, else it's own min-content/max-content size if the max track sizing function is min-content/max-content” ?

  6. Loirooriol commented on Jan 29, 2019

    @Loirooriol
    ContributorAuthor

    Basically yes, but IMO the sentence would bee too long and a bit confusing, there is already a min/max-content dichotomy for the size constraint, one could think that the this min/max-content is also with respect to that.

    I would prefer a refactoring like

    If the track has an auto min track sizing function, set the track’s base size to the maximum of its items’ foobars.
    The foobar of an item is calculated as follows:

    1. Let max be the max track sizing function if that is fixed, else the min/max-content contribution if the max track sizing function is min/max-content, respectively, else infinity.
    2. If the grid container is being sized under a min/max-content constraint, return the item’s min/max-content contribution, respectively, limited by max and floored by the item’s minimum contribution.
    3. Return the item’s minimum contribution, floored at zero.
  7. fantasai commented on Jan 29, 2019

    @fantasai
    Collaborator

    OK, I split the sentence. Didn't refactor the whole thing, but did some editorial tweaking to try to make it clearer. Let me know if the edits look OK and we'll ask for WG review. :)

  8. Loirooriol commented on Jan 30, 2019

    @Loirooriol
    ContributorAuthor

    Your refactoring with "limited min-/max-content contribution" looks good too.

    I'm just not sure about the use of "min-content/max-content size" instead of the preceding "min-/max-content contribution". Not much sure about the difference, I believe one is an inner size and the other an outer size, here you probably want the outer?

    And when it says "else by it’s own min-content/max-content size if that is min-content/max-content", "that" seems to refer to the own size instead of to the max track sizing function. Consider repeating "max track sizing function" to make it clear.

  9. fantasai commented on Jan 30, 2019

    @fantasai
    Collaborator

    You're right, that's clearly the wrong one. Done, and done. Thanks!!!

  10. fantasai commented on Jan 30, 2019

    @fantasai
    Collaborator

    Agenda+ to review the proposal:

    When sizing auto-minimum tracks under a min-/max-content constraint, we use the item's min-/max-content contribution. But we limit that contribution by the track's max size if it's fixed (length/resolved %). This change makes it so that we also limit the contribution in the case of a min-content/max-content max track size, which fixes Oriol's example above to yield more intuitive behavior.

    The value we're using to represent such an intrinsic max track size is the item's own contribution to such a size, which is I think a sufficient proxy for the actual max track size.

    CC @MatsPalmgren @mrego @javifernandez

  11. fantasai commented on Jan 30, 2019

    @fantasai
    Collaborator

    @Loirooriol I think actually we can simplify to only do this for min-content max track sizes, limiting by max-content seems like it'd be a no-op?

  12. 37 remaining items

  13. css-meeting-bot commented on Jul 18, 2023

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-grid] minmax(auto,min-content) under a max-content constraint, and agreed to the following:

    • RESOLVED: accept latest change
    The full IRC log of that discussion <fantasai> See https://github.com//issues/3565#issuecomment-1638901643
    <bramus> TabAtkins: if you look at very first comment, oriol has a test case here with some example and the wg decided earlier that chrome and edge are correct here.
    <bramus> … earlier we tried to implement that resolution in spec and we did it wrong, reverted, and did it again
    <bramus> … issue ended up being simpler thatn we thought
    <fantasai> Final fix was much simpler than we thought: https://github.com/w3c/csswg-drafts/commit/35ed93fc9296e6541e83c8cca4b705b7ba82c31a
    <bramus> … we believe only problem was in handling non spanning items in a max content constraint was
    <fantasai> s/max content/min content/
    <bramus> … we were using the limitex max content size
    <dholbert> s/limitex/limited/
    <bramus> … we should have been using limited min content size when resolving base sizes of tracks
    <bramus> … once we fixed that, algortihm made more sense in general
    <fantasai> s/of tracks/of auto tracks/
    <bramus> … this text also dated back to 2016 which was early in grid spec text, so we believe this was a mistake we made early on
    <bramus> … this mistake was not copied over into spanning case but firefox behavior in previous issue was them doing the same thing in spanning case
    <bramus> … if you do it in either case, it should be ok. we think spec text is ok now.
    <bramus> astearns: you were nodding along?
    <bramus> oriol: yeah, we discussed yeasterday and I think the current solution is the correct one
    <bramus> astearns: other comments?
    <bramus> astearns: proposed resolution to accept latest change as the solution to the earlier resolution
    <bramus> astearns: objections?
    <bramus> RESOLVED: accept latest change
  14. yisibl commented on Jan 23, 2024

    @yisibl
    Contributor

    Does this have a wpt test yet?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions