[css-grid-1] Distribution of intrinsic sizes according to flex factors doesn't handle sum < 1 · Issue #6078 · w3c/csswg-drafts (original) (raw)

Comments

@fantasai

https://www.w3.org/TR/css-grid-1/#algo-spanning-flex-items

if the sum of the flexible sizing functions of all flexible tracks spanned by the item is greater than zero, distributing space to such tracks according to the ratios of their flexible sizing functions rather than distributing space equally

Distribution of free space in “Expand Flexible Tracks” has special behavior for when the sum is less than one in order to get continuity between sum = 0fr and sum = 1fr, but this behavior is not reflected in the flex-dependent distribution rule under Resolve Intrinsic Track Sizes.

@Loirooriol

I already mentioned this possibility in #3694, but when we discussed it, not distributing the whole contribution didn't seem the right thing to do. Though I guess we could still distribute it all and have continuity by saying something like:

  1. If the sum of the flexible sizing functions is < 1, multiply the space to distribute by that sum.
    Otherwise use the space to distribute.
  2. Distribute that (if > 0) according to the ratios.
  3. Distribute the remaining space (if > 0) equally.

So, when distributing 100px among two flex tracks,

Tracks Current Continuous
0fr 0fr 50px 50px 50px 50px
0fr 0.1fr 0px 100px 45px 55px
0fr 1fr 0px 100px 0px 100px
0.1fr 0.3fr 25px 75px 40px 60px
0.2fr 0.6fr 25px 75px 30px 70px
0.3fr 0.9fr 25px 75px 25px 75px

@tabatkins

Yes, not distributing the space doesn't work here (since we're trying to size the tracks to the content, so they do need to grow). We currently distribute that space equally when the sum is 0, and proportionally when it is > 0. As shown by the first three rows in your table, your suggestion is a reasonable blend of the 0fr and 1fr behavior that creates continuity between the two states, so it sounds okay to us.

Agenda+ to confirm this change to the distribution rules is okay with the WG.

@css-meeting-bot

The CSS Working Group just discussed Grid 1 - sum of flex factures < 1, and agreed to the following:

fantasai added a commit that referenced this issue

Jul 2, 2021

@fantasai

… between zero and one. #6078

@fantasai

Edits checked in. @Loirooriol would you mind reviewing? (Close out the issue if it looks OK.)

@Loirooriol

@Loirooriol

Just some math, in case someone finds it useful.
When distributing among n tracks, the i-th one gets this fraction of the space:

where fⁱ is the flex fraction of thei-th track, and s = ∑fⁱ is the sum of flex fractions.