-
Notifications
You must be signed in to change notification settings - Fork 719
[css-sizing-4] Should aspect-ratio affect the intrinsic size? #5032
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
For SVG, the intrinsic aspect ratio is defined as distinct from the intrinsic width and height. An element can have an intrinsic height, an intrinsic aspect ratio, and still no intrinsic width: https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS However, in that case, the CSS default sizing algorithm kicks in to calculate the size of the other dimension. But different sizing algorithms can apply in other contexts (e.g., flexbox). Also see this HTML issue about how browsers don't currently expose intrinsic / “natural” sizes consistently for images: whatwg/html#3510 |
Looks like images don't let the aspect ratio affect the intrinsic size, so aspect-ratio probably shouldn't either: |
It should be 100px wide. Both the |
The fact that the image is wider than its max-content size when shrinkwrapped proves that the max-content size currently returned in layout is wrong. A shrinkwrapped box should never be wider than its max-content size, that is the maximum size of the formula. |
I agree that the definition of “intrinsic sizes” in https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes is rather confusing, because we've got a bit of circular logic:
It might be better to rewrite so the initial definitions is the “intrinsic max-content size” (which would be independent of aspect ratio), and then say the actual max-content size is that value if it is a definite value, or the result of the algorithm otherwise. That would also re-align the definition of “intrinsic size” for layout with the one from CSS images & SVG. |
Thinking about this and having off-list discussions with some implementors, @fantasai and I have come to some conclusions that we'd like to get WG review on. First, some design constraints:
Additionally, we want 'aspect-ratio' + 'min-size: auto' to have 'auto' resolve to the content height of a non-replaced element per #3268 (see minutes), so that the used height/width can violate the specified aspect-ratio if needed to prevent overflow. However, current implementations treat 'min-content' and 'max-content' as the natural size of an image, which is not consistent with the design constraints above: >
<img class=float src="https://placehold.it/50x50">
<img class=min-content src="https://placehold.it/50x50">
<style>
body { width: 1px; }
.float { height: 100px; float: left; }
.min-content { height: 100px; width: min-content; } An image with a naturalWidth of 50px, a 1:1 ratio, and "height: 100px" has, in implementations, a different width when floated in a zero-width container vs when it's assigned "width: min-content", which is wrong per the principles above, and not the behavior we'd want for non-replaced elements with 'aspect-ratio'. Implementors we discussed with from Blink and Gecko are optimistic that this behavior could be changed: replaced elements relying on an explicit non-prefixed 'min-content' or 'max-content' should be rare-to-nonexistent, since these relatively-obscure keywords grant no new abilities to replaced elements. So first, we want to verify with the CSSWG that this behavior can be changed, and that the spec is fine as-is. Assuming the existing definitions are acceptable, we are missing the ability to explicitly restrain one axis of a non-replaced element with an aspect-ratio to its widest atomic inline (min) or longest line of unforced content (max) or, more significantly, its content-based block size. We have defined 'min-height/width: auto' to have this functionality (see earlier remarks about #3268), but it has additional magic such as resolving to zero on scroll containers, so some additional keyword is still needed if we want to represent this behavior unconditionally. If we agree that such keywords would be useful for authors, we propose 'min-intrinsic' and 'max-intrinsic' for these keywords. These would match the concept already named “intrinsic” in 'contain-intrinsic-size' as well (since it is also prior to applying aspect-ratio). Either way, we can adopt such distinct terminology in the specs at least, to resolve #4961. ~ @tabatkins + @fantasai |
This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a
This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155}
This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155}
This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155}
What does: <div id="target" style="
min-width: max-content;
height: 100px;
overflow: hidden;
aspect-ratio: 1/1;">
<div style="width: 150px;">div>
div> ... |
(above is conditioned on): <div style="
min-width: max-content;
height: 100px;
aspect-ratio: 1/1;">
<div style="width: 150px;">div>
div> Resolving to |
Going from the notes in #5032 (comment) ... If we had I think that's the correct logic? We can consider some other logic, but, afaict that's what's outlined in #5032 (comment) |
(I think the |
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
So there are two different potential models
<div style="height: 100px; aspect-ratio: 1 / 1; width: max-content;">
<div style="display: inline-block; width: 150px;">div>
<div style="display: inline-block; width: 150px;">div>
div>
<div style="height: 100px; aspect-ratio: 1 / 1; width: max-content; min-width: 0;">
<div style="display: inline-block; width: 150px;">div>
<div style="display: inline-block; width: 150px;">div>
div>
<div style="height: 100px; aspect-ratio: 1 / 1; min-width: max-content;">
<div style="display: inline-block; width: 150px;">div>
<div style="display: inline-block; width: 150px;">div>
div>
<div style="height: 100px; aspect-ratio: 1 / 1; min-width: max-content;">
<div style="display: inline-block; width: 75px;">div>
div> Option 1
For this to work the current definition of the aspect-ratio-minimum is incorrect it likely wants to refer to the Things like flexbox etc, will also potentially need to refer to the
Option 2
E.g. if there is an aspect-ratio present, the
The aspect-ratio-minimum can still use the min-content definition here, (and likely other places like flex?) (I might update this in the morning, some things might be wrong). |
…zes with aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Add tests for intrinsic sizes with aspect-ratio This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155} -- wpt-commits: 36bf34ed4fbfa6769f8ae866c026628fd9c76544 wpt-pr: 24076
…zes with aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Add tests for intrinsic sizes with aspect-ratio This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155} -- wpt-commits: 36bf34ed4fbfa6769f8ae866c026628fd9c76544 wpt-pr: 24076
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1
In the short term, we will keep this as an internal value to implement the desired aspect-ratio behavior, where min-content will take the aspect ratio into account but we still need to be able to access the "real" min-content size to implement min-block-size: auto. In the longer term, CSS may add this as a length keyword with the same semantics and this prepares us for that. See also w3c/csswg-drafts#5032 Bug: 1045668 Change-Id: I76a290748e186b900bdbc2c4f5db8db55f6ce04f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255564 Commit-Queue: Ian KilpatrickReviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781117}
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431}
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431}
As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431}
And another question: Should min-content be affected by the aspect-ratio even if there is an explicit size in that axis? E.g.: <div style="width: 100px; height: 100px; aspect-ratio: 1/1; min-width: min-content;">
<div style="width: 200px;">div>
div> Should the width be 100px (from the aspect-ratio), or 200px (from the contents)? |
@cbiesinger In that example if we go with the logic in #5032 (comment) then I think one principle we need to make more explicit here is that resolving keyword sizes in a given axis requires ignoring all sizing properties in that axis, but might take into account sizing properties in the other axis due to an interdependency caused by layout rules or aspect-ratio. The min/max clamps are applied after all sizing properties in that axis are resolved to a length. |
@bfgeek So wrt Option 2... if we take the natural size of an image as analogous to the content size of a non-replaced element and maintain the correspondendance of min-content/max-content to the min/max extremes of shrink-to-fit, then Option 2 would break the current handling of floating images. Assuming we want to maintain the shrink-to-fit correspondence, we could take your interpretation only if we decide to break the content-size=natural-size analogy. Which is an interesting possibility! So, if I'm understanding correctly, option 2 could be:
But the problem with this is that it would give unexpected results for shrink-to-fit boxes. Consider your cases A-D as a float. The min-content size of the float would be 150px: if we put the float in a narrow box, it would not shrink below 150px, the size of its largest unbreakable content. This is fine, and probably what an author would expect. But if we place the float into a large container, it takes its max-content size, which would be 300px. This is not what an author would expect: they would expect the float to be its aspect-ratio-constrained width (floored by the min-content width if necessary), but no larger than that. This suggests that either (a) both min-content and max-content work off the min-content size and AR (probably confusing?) or (b) we give up and go back to Option 1, where the shrink-to-fit size of a non-replaced ratio-having element is solely determined by its ratio and the size in the other dimension (tho still floored by the 'min-width: auto', giving a width of 150px in this case) or (c) max-content no longer represents the max extreme of shrink-to-fit/fit-content, but is something else entirely?? [In both of (a) and (b) the behavior of min-content and max-content are identical to each other for any element with an aspect-ratio, but we can't figure out a way to make them different without falling to the unintuitive behavior outlined above.] Fwiw, our current inclination is to stick with Option 1 / #5032 (comment) Further thoughts? ~@fantasai and @tabatkins |
…ct aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Make intrinsic sizes respect aspect-ratio As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431} -- wpt-commits: c5f9e701753a034f99dda16d4716c465bed73e18 wpt-pr: 24157
…ct aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Make intrinsic sizes respect aspect-ratio As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431} -- wpt-commits: c5f9e701753a034f99dda16d4716c465bed73e18 wpt-pr: 24157
The CSS Working Group just discussed
The full IRC log of that discussion |
So the difference with "Option 2" is that we aren't actually using STF sizing in the float case. If we have a
Thoughts? |
@bfgeek Right; the idea of |
min/max/fit-content in the block axis is treated as auto: w3c/csswg-drafts#5032 Bug: 958381 Change-Id: Ieb8f189afc56a0cf2a49bf020115fd5d96017b6f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2726895 Reviewed-by: Christian BiesingerCommit-Queue: Rob Buis Cr-Commit-Position: refs/heads/master@{#859047}
… element. If the flex item is a non-replaced element and its min-width/min-height is 'auto', the spec has changed so that it has no transferred size suggestion now. https://drafts.csswg.org/css-flexbox-1/#min-size-auto This patch also updates WPT tests to fix #27878 Differential Revision: https://phabricator.services.mozilla.com/D112830 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1703304 gecko-commit: fb14e6d29a44a79efc296cc727f92aa58ea4dacc gecko-reviewers: dholbert
…ct aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Make intrinsic sizes respect aspect-ratio As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431} -- wpt-commits: c5f9e701753a034f99dda16d4716c465bed73e18 wpt-pr: 24157
…zes with aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Add tests for intrinsic sizes with aspect-ratio This adds the test case from https://crrev.com/c/2225827/5#message-a1b578693dd644b88f311c33833fd97254331706 It also adds a test for w3c/csswg-drafts#5032 and some other cases, and exposes a bug I wasn't aware of yet, https://crbug.com/1093094 [email protected] Bug: 1045668, 1093094 Change-Id: Ib4f76f05edffde99d8d8448c503775469e7da34a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238359 Auto-Submit: Christian BiesingerReviewed-by: Ian Kilpatrick Commit-Queue: Christian Biesinger Cr-Commit-Position: refs/heads/master@{#777155} -- wpt-commits: 36bf34ed4fbfa6769f8ae866c026628fd9c76544 wpt-pr: 24076
…ct aspect-ratio, a=testonly Automatic update from web-platform-tests [AspectRatio] Make intrinsic sizes respect aspect-ratio As discussed in w3c/csswg-drafts#5032 [email protected] Bug: 1093094, 1045668 Change-Id: Ic73428aef3a6cf426064e4b3824cfc5649e7c0c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241645 Commit-Queue: Christian BiesingerAuto-Submit: Christian Biesinger Reviewed-by: Ian Kilpatrick Cr-Commit-Position: refs/heads/master@{#781431} -- wpt-commits: c5f9e701753a034f99dda16d4716c465bed73e18 wpt-pr: 24157
https://drafts.csswg.org/css-sizing-4/#aspect-ratio
If an aspect-ratio is used, should it also affect the intrinsic size of a box? That is, should:
be 0px wide or 100px?
@bfgeek @tabatkins @fantasai
The text was updated successfully, but these errors were encountered: