Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[css-sizing] Define sizing of SVG Boxes with intrinsic aspect-ratio but no intrinsic size, in an auto-sized shrink-wrap parent #951
Comments
FremyCompany
added
css-sizing-3
CSS2
CSS22
labels
Jan 17, 2017
|
For completeness, Firefox behavior looks like to take the width of the last containing block that has a definite width (or the viewport). Looks like Edge and Chrome cap the object default width at that, but do not go higher. Might need more tests. |
|
I don't remember all the details, but I looked into similar questions of that when defining box-sizing and writing tests for it. If you're planing on writing tests on this topic, it could be worth looking at these for inspiration. |
|
It seems like Firefox's behavior is the most author-friendly. If @dbaron can explain how it works and convince everyone to follow, Tab and I think that would be the best course of action. |
fantasai
assigned
dbaron
Feb 16, 2017
fantasai
removed
CSS2
CSS22
labels
Feb 16, 2017
|
The Firefox behavior is fundamentally broken and shouldn't be copied. But it's possible that using an infinite max-content width will do what you want. But also see #1046. |
|
Infinite max-content width seems a bit problematic to render if someone explicitly requests it. :) But how about using the nearest scrollport width? That will nearly always be larger than the containing block width when you're doing shrink-to-fit, so will behave the same as infinity, but if you request it explicitly it'll still be a reasonable size. (This is also consistent with how we handle orthogonal flows when we need a size but don't have one.) |
fantasai
added
the
Agenda+ F2F
label
Jul 18, 2017
|
Intrinsic size computation can cross scrollports, so I don't think that works. The size of the scrollport might be a function of the intrinsic size of one of its ancestors, which was influenced by content inside the scrollport. |
|
Good point. We need to resolve on something definite for #1391 regardless, though, so once we figure that out we could use the same solution here. |
|
Possible solutions that have been suggested
I'm thinking nearest fixed-size scrollport is the best option (for this and the WM issue linked above). |
FremyCompany
referenced this issue
Jul 20, 2017
Closed
[css-sizing] Intrinsic Size of Images with Intrinsic Aspect Ratio and No Size #1609
AmeliaBR
commented
Jul 27, 2017
|
After the call today, I started building test cases to see what browsers are currently doing. The good news is that it's one big hot mess, so there is no clear cow-path to pave & we can decide on something sensible instead. Test cases with the results of testing on latest stable browsers |
AmeliaBR
commented
Aug 1, 2017
|
Coming back to this & summing up my thoughts (some of which are also in the conclusions section of the linked test pen): The issue with percentage sizing in a shrink-wrapped container isn't really SVG or aspect-ratio specific: I've tested it with other types of elements (e.g., Similarly, I think the issues of how borders and padding interact with sizing should be separate (and can probably be just called browser bugs. A nasty infestation of large quantities of browser bugs). So, on the subject of this issue: There are three auto-size behaviors seen in the tests:
|
astearns
removed
the
Agenda+ F2F
label
Aug 1, 2017
css-meeting-bot
commented
Aug 2, 2017
|
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Topic: Intrinsic Sizing of No Intrinsic Size Images<fantasai> https://github.com/w3c/csswg-drafts/issues/951#issuecomment-316535854 <fantasai> GitHub: https://github.com/w3c/csswg-drafts/issues/951#issuecomment-316535854 <TabAtkins> ScribeNice: TabAtkins <TabAtkins> fantasai: This issue is about a replaced element with an aspect ratio and no intrinsic size. <TabAtkins> fantasai: No intrinsic width or height, just ratio. What size will it be? <TabAtkins> fantasai: If you're not trying to compute intrinsic size, you use containing block width. <TabAtkins> fantasai: Stretch it to that, then use aspect-ratio to find the height. <TabAtkins> fantasai: But if you're shrinkwrapping around it, that's not usable. <TabAtkins> fantasai: So we need some kind of size to fall back to for this case. <TabAtkins> [pausing to talk to Amelia] <Rossen> AmeliaBR, we'll try and connect you <dbaron> AmeliaBR: message me an email address to email you the instructions <Rossen> [a number of people dragging all kids of equipment around - exiting!] <Rossen> AmeliaBR, we're now waiting for you <TabAtkins> ScribeNick: TabAtkins <TabAtkins> fantasai: There's a number of solution we could use, some aren't good, some are better. <TabAtkins> fantasai: The ones you were listing were: first, use 0, I agree it's bad. <TabAtkins> fantasai: Second is to inflate to the nearest container, but that requires doing layout, and dbaron said it's apparently insane and should not be followed. <TabAtkins> fantasai: Third you listed is to use 300px as width and calculate height from the aspect ratio. I think that's the first possible option. <TabAtkins> fantasai: Another option is to use the height or width of the ICB. <TabAtkins> fantasai: Another is to use the nearest container with any fixed size. <TabAtkins> fantasai: Another is nearest scroll container with a fixed size. <TabAtkins> fantasai: We have a similar problem for writing modes, where we need to find a default size when we have an orthogonal flow. <TabAtkins> fantasai: So it doesn't have an infinite inline size. <TabAtkins> fantasai: We originally specified using ICB height, but it was pointed out that's not the most useful thing if you're in a smaller scrolling container. <TabAtkins> fantasai: And so maybe we should use the height of the nearest scrolling container with a fixed height. <TabAtkins> fantasai: We could use that same solution here. <fantasai> TabAtkins: Find the nearest container options are similar to height: stretch problems <fantasai> TabAtkins: So might be as bad as that, not sure <fantasai> Myles_: Why not zero? <fantasai> fantasai: We try to avoid dataloss by default <fantasai> TabAtkins: Seems like 300px would be the easiest <TabAtkins> fantasai: Scrollport seems more useful. <TabAtkins> TabAtkins: WEll, minus intervening mbp, right? <TabAtkins> fantasai: No, just the width/height itself. <TabAtkins> TabAtkins: That'll often overflow then. <TabAtkins> fantasai: Yes, but you can scroll to it. <TabAtkins> Rossen: Usually. <fantasai> fantasai: But you can fit the image within the viewport at least if you scroll it into place <fantasai> s/viewport/scrollport/ <TabAtkins> AmeliaBR: Even though 300/150 is totally arbitrary, it is already being used in other cases where you don't have an aspect ratio at all. <tantek> like iframes <TabAtkins> fantasai: It's there because there had to be something, not because it's in any way useful. <TabAtkins> AmeliaBR: Yeah, but creating different rules means increasing the number of behavior differences, where you change one thing and the result dramatically changes. <Rossen> Rossen: but is going to be obstructed by scrollbars in cases of auto scrollbars depending on when the size is resolved. <TabAtkins> AmeliaBR: So "stick with what we already have" has some predictability to it. <TabAtkins> TabAtkins: Agree. <TabAtkins> dbaron: Other thing about 300/150 means it'll show up, and if it's not what you wanted, you can change it to something else. <TabAtkins> TabAtkins: As opposed to shrinking it to 0. <Rossen> and this is also a very new and random behavior that is even different than height/width: stretch <TabAtkins> dbaron: Yes. <TabAtkins> fantasai: Yeah, 0 is the worst option. <TabAtkins> Rossen: Yup, the 300px isn't great, but it's reliable and common, and if people don't like it, they can set the values explicitly. <TabAtkins> Florian: And while it's not useful, it's not dangerous; it won't usually cause overflow. <TabAtkins> fantasai: One thing for sure is that 0 should be min-content size. <TabAtkins> fantasai: Choosing an arbitrary min-content size prevents it from shrinking below that size, but the whole point of an image without intrinsic dimesnions is that it can shrink. <TabAtkins> TabAtkins: I agree with that. <TabAtkins> fremy: So a float would shrink it to 0? <TabAtkins> TabAtkins: Opposite - it'll be as large as possible there. Floats are *limited* to min-content below, but they try to be max-content size. <TabAtkins> RESOLVED: Replaced elements with only an intrinsic aspect ratio has a min-content size of 0 and a max-content size of 300px wide and 300*aspect-ratio height. <TabAtkins> AmeliaBR: Qualification is that it should be defined as inline size, not width. <TabAtkins> fantasai: Images actually are always upright, they dont' respond to writing mode. <TabAtkins> AmeliaBR: Like in vertical text, use 150px height, then 150*aspect ratio for width. <TabAtkins> fantasai: Not sure we want to have the sizing behavior change between horizontal and vertical WM. <dbaron> dbaron: Does css-writing-modes say how it revises CSS2 10.3.2 and 10.6.2? Should it? <TabAtkins> astearns: I think we should keep the resolution as-is, and have test-cases for it in WM to see what the behavior actually is, if we're interoperable. <TabAtkins> fantasai: WM does say how it revises those sections. <TabAtkins> fantasai: Currently this case is undefined in CSS2, so that's fine. <TabAtkins> fantasai: What it says about the case that is defined, is that it's analogous - you treat widths as the inline axis, etc, and translate the chapter 10 algos accordingly. <TabAtkins> fantasai: But it does say that images don't rotate and their intrinsic dimensions don't rotate. <TabAtkins> fremy: I checked in Edge, if you're using vertical text, we do use 150px height and 150*AR width. <TabAtkins> Florian: Is it annoying to have the intrinsic dimensions depend on something like WM? <TabAtkins> RESOLVED: In vertical WM, replaced elements with only an intrinsic aspect ratio use a 150px height and 150*aspect ratio width, instead. <TabAtkins> Florian: I ran into these sorts of bugs with testing box-sizing/svg/aspect ratio, and browsers behave different for aspect-ratio+height vs width+height. <TabAtkins> TabAtkins: Oh, that's bad. Having any 2 should be equivalent to having all 3. <TabAtkins> dbaron: Did you file bugs? <TabAtkins> Florian: I think I did where we had less than 2 correct cases. <TabAtkins> dbaron: Is there a test suite in WPT for this? <TabAtkins> Florian: Yes. |
FremyCompany commentedJan 17, 2017
Browsers seem to follow the recommendation when it applies, but the undefined behavior is not 100% interoperable though most browsers (Edge / Chrome / Safari) seem to fallback to the "default object width" and compute the height using the aspect ratio.
https://jsfiddle.net/2y31ru8u/
Maybe time to define an actual behavior?
cc @dbaron @fantasai