I have been unable to find any documentation to tell me one way or another.
Am I able to use object-fit cover on a canvas elements? I have done some experimenting and it is not behaving as expected.
Can somebody give me a definitive answer?
I have been unable to find any documentation to tell me one way or another.
Am I able to use object-fit cover on a canvas elements? I have done some experimenting and it is not behaving as expected.
Can somebody give me a definitive answer?
object-fit
1 will only work when there is a ratio change in order to correct it.Here is a basic example:
As you can see I defined a height/width for the canvas to be
200x200
(1:1 ratio) then I change this using CSS thus I break the ratio (we no more have a square) thenobject-fit
will correct this.A related question to understand the difference between setting width/height using attribute and using CSS: Why box-sizing is not working with width/height attribute on canvas element?
1From the specification we can clearly read that all the values (expect the default one
fill
) will try to maintain the ratio:The
none
value is a bit tricky but it basically mean keep the intrinsic default image size without scaling likecontain
orcover
Related: CSS object-fit: contain; is keeping original image width in layout