-
Notifications
You must be signed in to change notification settings - Fork 711
[css-sizing-4] Should aspect-ratio apply for width: auto; height: auto;? #5060
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
Comments
Similar question for |
I would expect all sizing for elements with a fixed For a block element in flow layout, that means that yes, the block size would be maximized to fit (after adjusting for padding/border, same as normal), and then the aspect ratio would determine the height. In other layout situations, different calculations would apply, but I think we now have defined algorithms for all these cases, including the flexbox one (if I recall correctly: it stretches to fit the row height, then the width gets calculated from the aspect ratio & becomes the flex-basis, but then flex grow or shrink applies and can distort the aspect ratio from its ideal). The main difference between a CSS box with aspect ratio, versus an image or SVG with an aspect ratio, would be in how min-content and max-content sizes are calculated, based on the normal rules for text/child CSS content instead of based on the intrinsic sizes of the replaced content. |
Yes, in the auto/auto case we do calculate the block size against the inline size using the aspect ratio. As @AmeliaBR points out, this is already defined because we had to define it for SVGs with an intrinsic aspect ratio and no intrinsic size, and
(If there's particular layout algorithms which don't handle this case, it needs a separate issue, since the problem applies to both such images as well as boxes with |
Closing the issue, since I think the spec already defines this and there's nothing to do here. |
@AmeliaBR So, I want to follow up on the flex item case. First I thought you were right, now I'm not sure. See: But https://drafts.csswg.org/css-flexbox/#algo-main-item happens before the cross-size determination. As such, I think the flex item case does require a |
@cbiesinger Are you only looking in Chrome? Because there is still cross browser inconsistency here. Chrome collapses elements to zero, Firefox does not, see modified version of your test case with SVG elements as well. @fantasai would probably remember better than I, but I'm pretty sure the WG consensus was that the “elements with aspect ratio but no defined size collapse to zero in flexbox” was a bad thing. 😏 If you want to work on tracking down the necessary tests & bug fixes, that would be greatly appreciated! Either way, the CSS box with aspect-ratio should behave the same as the SVG. |
…uto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291
Some relevant past issues & discussion: Resolution in #951 (comment) says “Replaced elements with only an intrinsic aspect ratio has a min-content size of 0” but see also #694 about clarifying the flexbox spec. The current relevant spec text is in the Flex Layout Algorithm:
I think if you follow all the linked definitions for terms, that says the Firefox behavior is correct. Note that the |
You convinced me for the |
So I'm not sure what's supposed to happen if it isn't stretched. I'm going to have to defer to the experts on this one (with a plea for maybe a few more editorial improvements or examples? If Chris and I can't figure out the spec, pity the poor mortals who don't do this for a living!) |
Yes, I was just going to point to that link :) (https://drafts.csswg.org/css-flexbox/#definite-sizes item 1) I filed https://crbug.com/1083020 in the meantime. |
Let me reopen this issue for now. |
Intriguingly, unlike the SVG, Firefox does not apply the right aspect ratio for @dholbert , what's up with that? :) |
…uto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291
…uto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360}
The distinction isn't that it is an |
…uto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360}
…uto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360}
In AmeliaBR's testcase with two SVG elements that she posted about above, I believe what's actually happening in Firefox is:
Here's a variant of Amelia's testcase with |
I'm not sure offhand why there's an img/svg difference, but Chrome & Firefox do agree on that being a difference. Here's an expanded version of your fiddle, comparing img vs. svg-with-intrinsic-size, for both |
Thanks @dholbert ; two questions:
|
I'm talking about how the lacuna value of the If the [width/height] attribute is not specified, the effect is as if a value of '100%' were specified. The value auto for width and height on the ‘svg’ element is treated as 100%. (I suspect this isn't meant to actually behave as 100% in this context, though, so this may be a Firefox bug.)
Your testcase here is comparing These attributes do different things, intrinsic-sizing-wise. The The Anyway -- the Chrome/Firefox difference on your second fiddle is merely an example of us (probably-mistakenly) using the lacuna "width=100%" value on the SVG element when establishing its flex-basis, as you can see if you add |
Ah... thanks for the spec reference. Anyway, my point with the width/height attribute was that it does not just set the intrinsic width, but it also makes the width specified. So we have a definite used flex basis and won't fall into the aspect ratio case here: https://drafts.csswg.org/css-flexbox/#algo-main-item Do you want me to file a bug on Gecko to not use 100% here? |
I see, that makes sense. So I think that means I'm already in the process filing a gecko bug on the 100% thing here (prepping a semi-comprehensive testcase) and I'll post it here when I've filed it. Thanks! |
(I'm not entirely sure the 100%-svg-flex-basis thing is a Firefox bug, actually. Firefox renders these two testcases the same, which makes sense to me; whereas Chrome renders them differently [and agrees with us on the first but not the second]. The only difference between the two is
|
I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1638937 on the SVG sizing-to-100% thing, BTW. The last piece of testcase 1 there ("Just viewBox") is the relevant bit where Chrome & Firefox differ. |
…even with width:auto;height:auto;, a=testonly Automatic update from web-platform-tests [AspectRatio] aspect-ratio should apply even with width:auto;height:auto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360} -- wpt-commits: bbf1f57cc2539e68e1a8d56685d2cae2eda9cc81 wpt-pr: 23625
…even with width:auto;height:auto;, a=testonly Automatic update from web-platform-tests [AspectRatio] aspect-ratio should apply even with width:auto;height:auto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360} -- wpt-commits: bbf1f57cc2539e68e1a8d56685d2cae2eda9cc81 wpt-pr: 23625
Funnily enough, this comment was posted just a few days after we committed the (mistaken, it turns out) simplification to the definiteness rules you asked for in #3531, which made this exact case no longer have a definite size. While reviewing this thread we realized it wasn't redundant at all, exactly for cases like this, and restored that text in ba8c7af, so now the spec is back to the expected behavior of the flex item having a definite cross size immediately (because it's stretched, and the flex container is single-line and has a definite cross size), so the aspect-ratio should activate and give the item a width of 100px.
A non-stretched item won't gain a definite height like the above; it'll fall through to Flexbox algo step 3 case E, in which its width becomes max-content, which per css-sizing-3 depends on its available inline size, which is defined in Flexbox step 2 as the inner size of the flex container. At this point its width becomes definite, so the a-r should then give it a height. (Note that this doesn't require it to flex; this happens prior to that step.) Firefox appears to get this case right, currently; Chrome for some reason keeps it at the naturalHeight regardless (testcase). So, this appears to be well-defined and in line with what we'd expect. We think there's nothing left to do for this issue, if that seems right shall we close it? |
Hold on, in that testcase, why does the max-content size depend on the available inline size? Are you suggesting this is due to the implied 100% width? (I would argue that this falls really into clause A), but I guess that doesn't really make a difference) I find it unintuitive that an |
Because when a replaced element has no intrinsic size, we have to come up with one, and that falls under the “For boxes with an intrinsic aspect ratio, but no intrinsic size” clause in https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes (which is itself extrapolated from the suggestion in https://www.w3.org/TR/CSS2/visudet.html#inline-replaced-width which leaves it otherwise undefined).
What other behavior would you suggest? Seems more useful to make sure it fits its container than to size it to zero or to arbitrarily pick 300px or something, imho! |
…even with width:auto;height:auto;, a=testonly Automatic update from web-platform-tests [AspectRatio] aspect-ratio should apply even with width:auto;height:auto; See discussion in w3c/csswg-drafts#5060 [email protected] Fixed: 1082479 Change-Id: Ic1f47a5ba92cdbff96ce0b1d60e9741c1051c291 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202691 Commit-Queue: Christian Biesinger <[email protected]> Auto-Submit: Christian Biesinger <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#769360} -- wpt-commits: bbf1f57cc2539e68e1a8d56685d2cae2eda9cc81 wpt-pr: 23625
https://drafts.csswg.org/css-sizing-4/#aspect-ratio
With
width: auto; height: auto; aspect-ratio: 1/1;
(in a horizontal writing mode), we still have a definite width, should we use that to calculate a height using the aspect ratio? Or should we requirewidth: 100%;
?/cc @bfgeek @fantasai @tabatkins
The text was updated successfully, but these errors were encountered: