Re: [csswg-drafts] [css-grid-1] Track Sizing Algorithm question (#2873)

I also analyzed the testcase with more detail after the meeting, but forgot to post my thoughts.

Basically, some confusing behavior of grid is that `auto` has completely opposite meanings when used as a min track sizing function vs a max track sizing function.

 - As a min track sizing function, it uses either the minimum contribution or the limited min-content contribution, which are both smaller than or equal to the min-content contribution. So the order is like `auto` <= `min-content` <= `max-content`.
 - As a max track sizing function, it behaves as `max-content`, except that it can be stretched at the end of the algorithm. So `min-content` <= `max-content` <= `auto`.

The example here uses `min-content, auto`, i.e. `mimax(min-content, min-content), minmax(auto, auto)`.
This is a somewhat contradictory input: the 1st track is requested to grow more as a minimum, but grow less a maximum. In CSS, minimums win, so that's why basically all of the contribution of the spanning item goes into the `min-content` track.

As Tab says, the effects vary a bit depending on the automatic minimum size. Removing the `overflow` distributes the size as a minimum contribution, so both rows get half of it since both are intrinsic. With `overflow`, the minimum contribution is 0, so the size is distributed as a min-content contribution, and it goes to the 1st track.

I don't think it's possible at this point to change the above. As fantasai says, to get the desired behavior, authors should use a different `grid-template-rows`, weakening the min track sizing function of the 1st track, and boosting the min track sizing function of the 2nd track.

```css
grid-template-rows: minmax(auto, min-content) minmax(min-content, auto);
```

That does the trick when the minimum contribution is 0, but otherwise the size will be distributed equally, just like with

```css
grid-template-rows: min-content minmax(min-content, auto);
grid-template-rows: minmax(auto, min-content) auto;
```

And it's at this point where I think we can improve the situation by doing what I said in https://github.com/w3c/csswg-drafts/issues/2873#issuecomment-1641000730

The growth limits have been set tight to the size of the non-spanning items, so if we prioritize respecting the limit of a track with a `min-content` max track sizing function over respecting the limit of a track with a `max-content` or `auto` max track sizing function, the extra contribution of the spanning item will go into the 2nd track.

-- 
GitHub Notification of comment by Loirooriol
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2873#issuecomment-1655978069 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 28 July 2023 16:34:39 UTC