In this article we can read:
The object-fit CSS property sets how the content of a replaced element, such as an
<img>
or<video>
, should be resized to fit its container.
What does container mean in this case?
Parent element? Containing block?
In this article we can read:
The object-fit CSS property sets how the content of a replaced element, such as an
<img>
or<video>
, should be resized to fit its container.
What does container mean in this case?
Parent element? Containing block?
From the specification:
So it's neither the parent element nor the containing block but the element itself. It's a relation between the element and it's content.
object-fit
change the behavior of the content based on the dimension of the element.Example with different elements sharing the same containing block:
In all the above cases, the
object-fit
will try to cover the200x200
area desfined by the width/height applied to the element. The containing block/parent element is irrelevant here and play no role.In the same specification you can also read the keyword "the content box" or "element's content box" which is the container your are looking for.
Related:
How does object-fit work with canvas element?
CSS object-fit: contain; is keeping original image width in layout