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] How to distribute space using flex ratios when the sum is 0? #3694

Open
Loirooriol opened this issue Mar 1, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@Loirooriol
Copy link
Collaborator

commented Mar 1, 2019

From https://drafts.csswg.org/css-grid/#algo-spanning-flex-items,

Increase sizes to accommodate spanning items crossing flexible tracks: Next, repeat the previous step instead considering [...] all items that do span a track with a flexible sizing function while [...]

  • distributing space to such tracks according to the ratios of their flexible sizing functions rather than distributing space equally

This "according to the ratios" seems slightly ambiguous to me.

What if the sum of ratios is 0? Then each track should get a 0/0 fraction of the distributed space, doesn't make sense. I guess in this case space is distributed equally, like for non-flexible tracks.

I think it would be more clear if the algorithm said:

  • Non-flexible tracks have a weight of 0.
  • Flexible tracks have a weight of their flex fraction.
  • When distributing space among some tracks, sum their weights. If this is is 0, the space is distributed equally. Otherwise, each track receives a share of its weight divided by the sum of weights.

This should be in the real algorithm, https://drafts.csswg.org/css-grid/#extra-space, not as some kind of vague amendment in https://drafts.csswg.org/css-grid/#algo-spanning-flex-items

Alternatively, not sure if something special should happen when the sum of weights is less than 1, akin to

<flex> values between 0fr and 1fr have a somewhat special behavior: when the sum of the flex factors is less than 1, they will take up less than 100% of the leftover space.

fantasai added a commit that referenced this issue Jun 6, 2019

@fantasai

This comment has been minimized.

Copy link
Collaborator

commented Jun 6, 2019

OK, yeah, we definitely need to fix the divide-by-zero case. :) I agree with the behavior you describe, but, while I think your weighting algorithm is very clever in how it can handle the space distribution of both steps, it makes the section a bit harder to digest. So I'm keeping the current structure, but adjusting the step that assigns weights to match your suggestion.

Agenda+ to request review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.