Re: [csswg-drafts] [css-grid][css-contain] Clarify that `contain:size` affects track sizing (#4931)

> In your first comment you say that the track size should be 0, seemingly implying that you only want to run the TSA without items, never with items.

Right, that's option A.

> In your last comment you seem to mean that you want to ignore `grid` (so that you can avoid running the TSA) when sizing the grid container under a min/max-content constraint. And then run the TSA once with items when laying out for real.

No, I never said `grid` should be ignored. On the contrary, running the TSA is how you take `grid` into account. You can run it without items though. Then definite track sizes are still sized normally, but intrinsic track sizes will be zero. So option B (that I described in my last comment) is to run the TSA once _without_ items for calculating the intrinsic content-box size of the grid container, and then a second time _with_ items when "laying it out for real" (so that the final track sizes are sized normally as if `contain:size` weren't specified). The grid container's intrinsic size would still be taken from the first step though (the first step isn't needed if it has a definite size obviously). So for example:
```html
<div style="display:inline-grid; contain:size; grid:auto 100px / auto 200px">
  <item><div style="width:300px; height:300px"></div></item>
</div>
```
with option A:
the grid container content-box size is `200px x 100px`
the resolved track sizes are `0px 100px / 0px 200px`
the item's content-box size is `0px x 0px`
with option B:
the grid container content-box size is `200px x 100px`
the resolved track sizes are `300px 100px / 300px 200px`
the item's content-box size is `300px x 300px`

> So not sure I understand your proposal.

I've described two different options (so far). I hope they are clear now.

BTW, I'm assuming above that the [grid item placement step](https://drafts.csswg.org/css-grid/#placement) in the Grid layout algorithm _always_ occurs, also for `contain:size`.  But this isn't at all clear from the [CSS Containment spec](https://drafts.csswg.org/css-contain/#size-containment). In fact, a strict reading of the spec implies that **it shouldn't occur**: "_When calculating the size of the containing box, including when computing its intrinsic size, it must be treated as having no contents._"

The "_treated as having no contents_" implies that implicit tracks should **not** be created (since there are no items if we treat it as having no contents), for example:
```html
<div style="display:inline-grid; contain:size; grid-auto-rows:100px; grid-auto-columns:100px">
  <item></item>
</div>
```
Chrome makes the grid container content-box size `100px x 100px`, i.e. clearly not treating it as empty when computing its intrinsic size, which contradicts what the spec text currently says.

So the spec needs to say explicitly which parts of Grid layout are supposed to be run with/without items, unless it means all of them.

I don't have a strong opinion on which option to choose. Option B seems to be close to what Chrome is currently doing and that seems to be the behavior you guys prefer, so that's fine with me.  It needs to be clearly specified how it's actually supposed to work though, because the current spec text suggests something completely different.

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

Received on Saturday, 11 April 2020 23:44:07 UTC