Open bfgeek opened 3 years ago
The CSS Working Group just discussed [css-images] Behaviour of SVG degenerate aspect-ratios
.
@AmeliaBR you were tagged in the SVG issue. We are waiting for your input on how to handle this case.
Ping @AmeliaBR @fantasai
I'm really sorry all, this kind of testing & synthesis / cross comparison is beyond my current cognitive capabilities. I've got it at the top of my to-do list for a good brain day, but it's been a month, so please continue without my input.
My only suggestions are to cross reference what browsers currently do, looking at both SVG as image and
If you have any specific questions that can be asked & answered in tweet-size pieces, let me know.
looking at both SVG as image and
For this specific case its slightly important that we use an "SVG as an image", as a "width: 0" has meaning within CSS, which makes us "ignore" the aspect-ratio (consistently between implementations).
However we can look at the behaviour of "width: -1px" which does have significant implementation differences, consider:
<!DOCTYPE html>
<style>
img, svg {
border: solid;
background: lime;
}
</style>
<img style="width: 100px" src="
data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='-1px' height='50px' viewBox='0 0 1 1'></svg>">
<svg style="" xmlns="http://www.w3.org/2000/svg" width="-1px" height="50px" viewBox="0 0 1 1"></svg>
<svg style="width: -1px; height: 50px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>
OR
<!DOCTYPE html>
<style>
img, svg {
border: solid;
background: lime;
}
</style>
<img style="height: 100px" src="
data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='-1px' height='50px' viewBox='0 0 1 1'></svg>">
<svg style="" xmlns="http://www.w3.org/2000/svg" width="-1px" height="50px" viewBox="0 0 1 1"></svg>
<svg style="width: -1px; height: 50px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>
Here Blink's behaviour (post M93 - we've fixed lots of bugs in this area) and Safari is "treat -1px as invalid, and fallback to the viewBox aspect-ratio". Gecko's behaviour is "treat -1px as 0px when defined as an SVG attribute however in CSS ignore -1px and fallback to the aspect-ratio".
I somewhat prefer Blink/Safari behaviour of consistently treating "-1px as invalid here".
This however is only about a "clearly invalid" value of -1px. 0px is valid for intrinsic sizing purposes and the question if it should fallback to the viewBox aspect-ratio still remains.
<!DOCTYPE html>
<style>
img, svg {
border: solid;
background: lime;
}
</style>
<img style="width: 100px" src="
data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='0' height='50px' viewBox='0 0 1 1'></svg>">
<svg style="" xmlns="http://www.w3.org/2000/svg" width="0" height="50px" viewBox="0 0 1 1"></svg>
<svg style="width: ; height: 50px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>
Here the intrinsic-size is clearly 0x50. But does the aspect-ratio fallback to the viewBox to be 1/1 or not? This somewhat depends on how "-1px" is handled.
One quick note: style="width: -1px" should be rejected & ignored at the parser level. If you want to test auto width, best to say so explicitly. To test the default stylesheet width, you could leave off or use a revert keyword where supported. But that might depend on how the default stylesheet integrates presentational width attributes.
The CSS Working Group just discussed SVG degenerate aspect ratios
, and agreed to the following:
RESOLVED: degenerate aspect ratios derived from SVG width/height attributes fall back to viewbox aspect ratio (whether due to negative values or zero values)
This issue is mainly just so that we can discuss this SVGWG issue: https://github.com/w3c/svgwg/issues/848
There are a few tests in the css-grid testsuite asserting behaviour.