Questions tagged [object-fit]

The object-fit CSS property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.

The object-fit CSS property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.

Syntax

The object-fit property is specified as a single keyword chosen from the list of values below.

Values

  • fill (Initial value) - The replaced content is sized to fill the element’s content box: the object’s concrete object size is the element’s used width and height.

  • contain - The replaced content is sized to maintain its aspect ratio while fitting within the element’s content box: its concrete object size is resolved as a contain constraint against the element’s used width and height.

  • cover - The replaced content is sized to maintain its aspect ratio while filling the element’s entire content box: its concrete object size is resolved as a cover constraint against the element’s used width and height.

  • none - The replaced content is not resized to fit inside the element’s content box: the object’s concrete object size is determined using the default sizing algorithm with no specified size, and a default object size equal to the replaced element’s used width and height.

  • scale-down - The content is sized as if none or contain were specified, whichever would result in a smaller concrete object size.

References

Browser Support

113 questions
0
votes
2 answers

Images to fit its container preserving size ratio

I have several images to render and I want them to keep the same size ratios as they are. For instance, if there is a person with a height of 183cm and another with 170cm, I would like them to preserve those differences in comparison between them,…
Joaquin Palacios
  • 287
  • 8
  • 33
0
votes
1 answer

aspect-ratio with dynamic width and height, similar to object-fit contain

I have a container element (chocolate color on screenshot), that contains a grid of tiles 3x2. The tiles contains image element with 16/9 resolution image and some header and footer. The tiles span can be 1-3 with 4px gap in between. The image is…
niio
  • 326
  • 3
  • 15
0
votes
1 answer

How to calculate the rendered dimensions of an image styled with object-fit: contain

I have this simple html showing an image. Image Object Fit