Open jakearchibald opened 2 years ago
cc @jensimmons
Oh, huh, this seems like an obvious oversight. Definitely needs fixing, and should be fixable with a bit of tweaking.
I guess images/objects could have a "first resource size pending" boolean, which would be false by default. However, images and videos would immediately set it to true, and only set it to false once width/height is gained from the resource.
With aspect-ratio: auto 16 / 9
, the 16 / 9
part would be used while the "first resource size pending" is true.
If an image/video's source is changed, "first resource size pending" is not reset to true.
Okay, so this actually would require an edit to Images 3, since that's where the dimensions are defined. Agenda+ to add the concept of "pending resource-based size", so Sizing can hook that for aspect-ratio: auto
.
Dunno if it's worth calling it "pending first resource-based size". When changing the src
of the image/video, it should keep using the previous resource-based size until it has updated data. I believe that's what currently happens with <img>
.
The CSS Working Group just discussed aspect-ratio via width/height doesn't work for <video>
, and agreed to the following:
RESOLVED: Clarify that aspect-ratio:auto doesn't pull aspect ratio from the default object size, it can only pull from an actual loaded resource
The default object size is not a natural size, and doesn't have an aspect ratio. It shouldn't be providing an aspect ratio to the aspect-ratio property in the first place.
I think it's also worth pointing out that the default object sizing algorithm defined in https://www.w3.org/TR/css-images-3/#default-sizing does not apply to replaced elements.
Firefox patch: https://bugzilla.mozilla.org/show_bug.cgi?id=1783069
I don't know if it's the right place to put this but I ended up on this thread because I had this exact issue. After some testing I found a workaround until it's fixed on the browser level. The idea is to put a transparent svg image with the same width and height as poster
and then the initial ratio is good... here is an example for a 1000x600 video:
<video width="1000" height="600" poster="data:image/svg+xml;utf8,<svg width='1000' height='600' xmlns='http://www.w3.org/2000/svg'></svg>">
<source src="video.mp4" type="video/mp4">
</video>
Just in case it can help others.
https://github.com/whatwg/html/pull/6529 attempted to solve https://github.com/whatwg/html/issues/4961 (auto aspect-ratio) for
<img>
and<video>
. It works for<img>
, but it doesn't work for<video>
.The problem is,
<video width="16" height="9" …>
creates an internal style rule likeaspect-ratio: auto 16 / 9
.The
auto
part means the provided ratio (16 / 9
) is ignored once the element has a natural aspect ratio.Images start off without a natural aspect ratio, and they gain one once the resource is loaded enough to know its dimensions. The benefit is, if the provided
width
andheight
are wrong, that information is discarded in favour of the accurate values from the image resource.However,
<video>
has a defined default object size of 300x150, meaning the aspect ratio derived from the width and height attributes is instantly ignored in favour of300 / 150
. So, although browsers are generating theaspect-ratio
rule for<video>
, it's useless.We can't just remove the default object size from
<video>
, otherwise it'd be 0x0 by default, which would break cases where the element didn't have a width and height set, and the browser doesn't attempt to fetch the video until some kind of interaction. Because the element would be 0x0, that interaction would be impossible.So, it feels like the definition of
auto
inaspect-ratio
needs to altered in some way so the provided ratio has higher priority than the default object size.