Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-grid] Automatic minimum sizes should never force grid items to become bigger than the tracks they span #3705

Closed
Loirooriol opened this issue Mar 4, 2019 · 2 comments

Comments

@Loirooriol
Copy link
Contributor

https://drafts.csswg.org/css-grid/#min-size-auto says

to prevent the content-based minimum size from forcing overflow of its fixed-size grid area, if in a given dimension the grid item spans only grid tracks that have a fixed max track sizing function, then [... the content-based minimum size is ...] further clamped to less than or equal to the stretch fit into the grid area’s maximum size in that dimension, as represented by the sum of those grid tracks’ max track sizing functions

In fact this is not correct. I agree that clamping by the sum of max track sizes seems a good heuristic, but not doing so wouldn't force the item to overflow its fixed-size grid area. That's because the content-based minimum size is only used when an item spans a track with an auto min track size, and if all spanned tracks have a fixed max track sizes then they are not flexible. Therefore, https://drafts.csswg.org/css-grid/#algo-spanning-items ensures the sum of the spanned track sizes will at least be the minimum contribution of the item, which is greater or equal than the outer size given by the minimum size. So not clamping would just imply that both the item and the tracks it spans would be larger, but no overflow.

So the paradox is that when there is clamping, it's not actually needed to prevent overflow; but when there is no clamping because some track doesn't have a fixed max size, then the automatic minimum size may force a grid item to become bigger than the tracks it spans.

Basically, this happens when

Example: https://jsfiddle.net/jLfwga63/

<div id="grid">
  <div id="item"></div>
</div>
#grid {
  display: grid;
  width: 0;
  grid-template-columns: auto minmax(0px, 1fr);
}
#item {
  grid-column: 1 / 3;
  background: cyan;
}
#item::before {
  content: '';
  display: block;
  width: 100px;
  height: 100px;
}

The automatic minimum width is 100px, but both columns are 0px wide, so the item is forced to overflow. This seems bad, in order to prevent it, consider dropping

distributing space only to flexible tracks (i.e. treating all other tracks as having a fixed sizing function of their current base size)

at least in case all spanned flexible tracks have a fixed min track sizing function.

@fantasai
Copy link
Collaborator

fantasai commented Jun 6, 2019

Here's the comment summarizing the principles that led to the text handling flexible tracks: #2177 (comment)

As far as we can tell, there are two principles here that we want to follow:

  • Flexible tracks absorb spanning items' content, leaving auto tracks tightly-wrapped around their contents insofar as possible. (See [css-grid] Grid track sizing items spanning a flexible track #2177 (comment))
  • Content-sized tracks such as auto tracks and flexible tracks with a minimum (e.g. minmax(min-content, 1fr) honor their minimum and ensure that no item spanning them causes overflow.

fantasai added a commit that referenced this issue Jun 6, 2019
…ldn't trigger overflow, elide the informative text stating that purpose from the sentence describing the clamping. Requested by Oriol. #3705
fantasai added a commit that referenced this issue Jun 6, 2019
…xed tracks, to make sure spanning items get accommodated by the intrinsic tracks they cross. #3705
fantasai added a commit that referenced this issue Jul 28, 2020
…ks do not contribute to inflexible intrinsically-sized tracks. #4783"

This reverts commit 90511c6.
@fantasai
Copy link
Collaborator

Update: In #4783 we reverted this fix and made a different one (clamping the automatic minimum size to zero when it crosses flexible tracks).

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Mar 29, 2021
This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Mar 29, 2021
This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Mar 29, 2021
This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}
pull bot pushed a commit to FreddyZeng/chromium that referenced this issue Mar 30, 2021
This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 2, 2021
…nsic-sizes-002.html, a=testonly

Automatic update from web-platform-tests
[css-grid] Fix WPT grid-flex-track-intrinsic-sizes-002.html

This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}

--

wpt-commits: 4fb0b5be59092eecdb9ef0cd03180f2f9a423f1d
wpt-pr: 28291
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 2, 2021
…nsic-sizes-002.html, a=testonly

Automatic update from web-platform-tests
[css-grid] Fix WPT grid-flex-track-intrinsic-sizes-002.html

This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}

--

wpt-commits: 4fb0b5be59092eecdb9ef0cd03180f2f9a423f1d
wpt-pr: 28291
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 7, 2021
…nsic-sizes-002.html, a=testonly

Automatic update from web-platform-tests
[css-grid] Fix WPT grid-flex-track-intrinsic-sizes-002.html

This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}

--

wpt-commits: 4fb0b5be59092eecdb9ef0cd03180f2f9a423f1d
wpt-pr: 28291
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 8, 2021
…nsic-sizes-002.html, a=testonly

Automatic update from web-platform-tests
[css-grid] Fix WPT grid-flex-track-intrinsic-sizes-002.html

This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}

--

wpt-commits: 4fb0b5be59092eecdb9ef0cd03180f2f9a423f1d
wpt-pr: 28291
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
This test was checking that grid items not spanning any flex track with
an intrinsic min track sizing function would distribute its intrinsic
contribution in $11.5.3. That was according to the resolution from
w3c/csswg-drafts#3705

However, that wasn't web compatible, so it was later amended in
w3c/csswg-drafts#4783

Now, the intrinsic contributions of items spanning flex tracks must be
distributed in $11.5.4, even if none of the flex tracks is intrinsic.

This change makes the test pass in GridNG.

Bug: 1045599
Change-Id: Ibfb818dcc12a185e30d2824e9ca534069beb48ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2791426
Reviewed-by: Javier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#867283}
GitOrigin-RevId: 762ea1b8feb239644f4c1073af42fc639959a6f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants