[csswg-drafts] [css-sizing-4] aspect-ratio via width and height attributes doesn't work for <video> (#7524)

jakearchibald has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-sizing-4] aspect-ratio via width and height attributes doesn't work for <video> ==
https://github.com/whatwg/html/pull/6529 attempted to solve https://github.com/whatwg/html/issues/4961 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 like `aspect-ratio: auto 16 / 9`.

The `auto` part means the provided ratio (`16 / 9`) is ignored once the element has a [natural aspect ratio](https://drafts.csswg.org/css-images-3/#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` and `height` are wrong, that information is discarded in favour of the accurate values.

However, `<video>` has a [defined default object size](https://html.spec.whatwg.org/multipage/media.html#the-video-element:default-object-size) of 300x150, meaning the aspect ratio derived from the width and height is instantly ignored in favour of `300 / 150`. So, although browsers are generating the `aspect-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` in `aspect-ratio` needs to altered in some way so the provided ratio has higher priority than the default object size.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7524 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 22 July 2022 12:20:39 UTC