Skip to content

[css-flexbox-1] Clarify fit-content behavior when the available space in a given axis is indefinite #11414

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

Closed
gitspeaks opened this issue Dec 25, 2024 · 5 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-flexbox-1 Current Work

Comments

@gitspeaks
Copy link

gitspeaks commented Dec 25, 2024

According to CSS Flexible Box Layout Module, Section 9.4(7):

Determine the hypothetical cross size of each item by performing layout with the used main size and the [cross-axis*] available space, treating [flex item cross-size*] auto as fit-content.

However, according to the CSS Box Sizing Module Level 3, Section 2.1, the fit-content size in a given axis depends on the available space being definite:

If the available space in a given axis is definite, equal to clamp(min-content size, stretch-fit size, max-content size) (i.e. max(min-content size, min(max-content size, stretch-fit size)))

In particular, stretch-fit size is:

Undefined if the available space is indefinite.

and

Calculations involving this size need to specify a fallback behavior for when the available space is indefinite if that happens to be possible.

This raises a question: How should the fit-content value be determined for a flex item in situations where the [cross-axis*] available space is indefinite?

Consider the following scenario:

  • Writing Mode: horizontal-tb
  • Flex Direction: row
  • Flex Container and Flex Items: Both have height: auto.

How should the fit-content size for the cross axis (height) of the flex item be determined?

Note: This step takes place after Section 9.7

(*) Added for clarification purposes.

@Loirooriol
Copy link
Contributor

That isn't specific to flexbox, you removed it but the quote even says "as if it were an in-flow block-level box".

https://drafts.csswg.org/css-sizing-3/#fit-content-size

When sizing under a min-content constraint, equal to the min-content size. Otherwise, equal to the max-content size in that axis.

Also see #10721

@Loirooriol Loirooriol added css-flexbox-1 Current Work Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. labels Jan 3, 2025
@gitspeaks
Copy link
Author

That isn't specific to flexbox, you removed it but the quote even says "as if it were an in-flow block-level box".

I didn't remove anything. I mistakenly included a link to the draft instead of the published version, where it clearly states:

Determine the hypothetical cross size of each item by performing layout with the used main size and the available space, treating auto as fit-content.

This is how the specification should be read as published.

@gitspeaks
Copy link
Author

When sizing under a min-content constraint, equal to the min-content size. Otherwise, equal to the max-content size in that axis.

Just to confirm I understand correctly, the process is:

Treat the flex item as a block-level box in flow layout, where the available space in the main direction is determined by the previously calculated main size. Since the flex item's cross size is set to auto, we use fit-content and because the flex container has height: auto which does not impose a min-content constraint , the fit-content will be determined using max-content sizing in the cross direction — specifically, the max-content block size in case the cross direction is block.

Is that correct?

@Loirooriol
Copy link
Contributor

where the available space in the main direction is determined by the previously calculated main size

The calculated main size is used as the main-axis size of the item, not as the available space in the main-axis.

@gitspeaks
Copy link
Author

The calculated main size is used as the main-axis size of the item, not as the available space in the main-axis.

My intention was: 'available space' for the block-level box in a flow layout.

For horizontal-tb / row, read:

Treat the flex item as a block-level box in flow layout, where the available space in the inline direction (for the block-level box in flow layout) was determined by the previously calculated inline size of that box when it was considered a 'flex item.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-flexbox-1 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants
@Loirooriol @gitspeaks and others