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

Why doesn't the image element resize to its real proportion under flexbox with object-fit: contain?

I have a container where multiple images will appear in succession (a slide show). Some images are in landscape format, others in portrait. There are also two side panels that should occupy the remaining space on the left and right sides of the…
Rodrigo
  • 4,706
  • 6
  • 51
  • 94
0
votes
3 answers

Is there a way to transform scale without stretching an Object Fit?

If I am using a transform scale is there a way to keep the object fit image using cover from stretching? Here is my code div.category { width: 80%; height: 150px; margin: 20px; position: relative; overflow: hidden; } img { …
Chris Grim
  • 149
  • 1
  • 6
  • 20
0
votes
1 answer

object-fit: cover compatibility differences according to Mozilla and caniuse

I am wondering what browsers support the CSS property object-fit: cover. I usually use a mixture of Mozilla browser compatibility table and caniuse, however, they provide slightly different information. For example, on Mozilla, Chrome for Android…
Corbuk
  • 670
  • 1
  • 8
  • 23
0
votes
0 answers

CSS Object-fit and aspect-ratio

I have a small problem with css property object-fit and/or aspect-ratio. Context: I have a block (a big link) containing an image and some text. The image is of unknown dimensions and aspect ratio. I want to force the image dimensions, without…
MarvinLeRouge
  • 444
  • 5
  • 15
0
votes
0 answers

How can I make a fixed-position element escape a 3D-transformed element?

I have an element that has a CSS 3D Tranform applied to it. Inside that element is a video that I want to use as a background, using position: fixed and object-fit: cover. Without altering the shape of the DOM, and without removing the 3D Transform…
Kerrick
  • 7,420
  • 8
  • 40
  • 45
0
votes
1 answer

Why is object-fit: contain/cover; not having an effect?

Why does object-fit: contain/cover; have no effect?
tonitone
  • 54
  • 6
0
votes
1 answer

Responsive square img (padding-bottom: 100%) not working on iOS?

I have a grid of "Related posts" in my blog and tried the padding-bottom: 100% trick to make the image of each post responsive square. It works on desktop but on mobile iOS the height of the images stretches to 100% of the viewport. On Samsung phone…
Vito
  • 179
  • 1
  • 14
0
votes
2 answers

How do I use object-fit with a 16:9 image?

I'm trying to figure out how to use object-fit to properly scale a 16:9 vertical image. I've tried almost anything with no luck! https://jsfiddle.net/pdocys3j/ .container { width: 300px; /*any size*/ height: 200px; /*any…
alvincrespo
  • 9,224
  • 13
  • 46
  • 60
0
votes
2 answers

why are my images shaking while i hover mouse on the image div

I am making an image gallery using just html, css(flexbox). The problem is this that the images inside the div are shaking while mouser hover when i am using object-fit: cover property on the images. * { …
user8826283
0
votes
1 answer

Div and Image vertically missalligned when height: 100vh

Can someone please tell me why the div and the image are vertically separated?
TEST
SICK SHOT
Schweini
  • 17
  • 2
0
votes
0 answers

Image magnification object-fit: cover squashing image

I have been working on a jQuery image magnification solution, which is almost working perfectly. However (and I believe this may be to do with using object-fit: cover) when the image is magnified, it is slightly distorted. The background-size of the…
dungey_140
  • 2,602
  • 7
  • 34
  • 68
0
votes
1 answer

Scale down within grid container so, that retains its aspect ratio

I have a problem scaling down canvas elements that belong to grid container. html * { font-size: 1em; font-family: Arial; } #wrapper { border: 1px solid green; display: grid; grid-template-columns: repeat(auto-fit, 32vmin); …
user14063792468
  • 839
  • 12
  • 28
0
votes
2 answers

Div maintaining original size image without stretching / overflowing

I have an html page like this :