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
1
vote
2 answers

How to scroll height of image inside a grid when object-ft: cover and object-position: center top

I have created an image gallery using flex. The images are columns where the width of each image is adjusted so that the gallery fits the width of the flex container. When a user hovers over an image in the gallery the image grows and shows its full…
JessicaRyan
  • 115
  • 3
  • 14
1
vote
0 answers

Object-Fit Cover not working on Safari Mobile

I've noticed a small problem. The object-fit: cover doesnt seem to work on Safari Mobile. Is there any workaround for it? If u can see in the image, the background image is leaking out of the container. Below is a snippet of my code: …
hoseh
  • 129
  • 1
  • 3
  • 14
1
vote
3 answers

object-fit:contain on child prevents parent event from triggering

let parent = document.getElementById("parent"); let img = document.getElementById("img"); parent.addEventListener("click", function() { parent.style.display = "none"; }); img.addEventListener("click", function(e) { …
atan
  • 58
  • 2
  • 10
1
vote
1 answer

Object-fit doesn't work with fixed width and height

.block { width: 500px; height: 300px; } img { max-width: 100%; object-fit: contain; }
In my opinion, the…
KAVA
  • 197
  • 1
  • 4
  • 16
1
vote
1 answer

object-fit not working, did the container affect the object-fit

the object-fit is not working, I don't know why. it only works with inline-style in the image tag. can anyone explain, please? maybe the hero_media container affecting the object-fit?. I'm also trying to use a pseudo-element (after and before ) to…
Murwan eisa
  • 141
  • 1
  • 2
  • 8
1
vote
1 answer

Img using `object-fit: cover` still increases height of parent

I'm building a component that will have variable content. So I'd like the img to respond like a bg img, taking the height of it's container rather than defining the height. Even when I define add object-fit: cover though, the img still affects the…
E-video
  • 47
  • 7
1
vote
2 answers

how to insert a full screen large background image in html,css?

The full image is not displayed properly, the bottom of the image is missing, how can I display the full image on screen? (dimensions: 5904 * 4000 px) I tried with object fit but its not working: * { margin: 0; padding: 0; } header { width:…
1
vote
1 answer

CSS positioning of off-center image

I need to center the mobile phone. Here is what is included in the mockup: However, this is what I'm getting: How can I position/center the mobile image so that the shadow doesn't push the phone to the right? I'm using display: flex; HTML
Michelle M.
  • 515
  • 1
  • 7
  • 20
1
vote
1 answer

Resizing clipped part of the image with CSS

I am trying to figure out, if there is any way to resize the clipped part of the image with use of css. In the most expected version, image resized this way should keep the imposed aspect ratio. I was playing with clip-path, trying both approaches…
dra89szka
  • 103
  • 1
  • 11
1
vote
1 answer

Fit multiple images into a single table cell

I am having some issues with sizing images. I have images that I have created with photoshop. They are all PNG's and have cropped them to remove as much white space as possible, but one image is moved to the right a bit. Since I'm using a table, I…
Eltik
  • 71
  • 6
1
vote
0 answers

Image sets minimum height on CSS Grid?

I'm trying to set up a grid layout, which has images with object-fit: cover on them, however this seems to set a minimum height on the grid layout. Is this intended, or am I doing something wrong? Here's my markup:
skxc
  • 275
  • 1
  • 2
  • 13
1
vote
0 answers

Object-fit: cover lightbox gallery fix in IE?

I am using a flexbox gallery with a lightbox that unfortunately uses object-fit: cover, which does not work in Internet Explorer. I have attempted several fixes, but any script with uses these images as a background image prevents the lightbox…
Jaden Hilgers
  • 33
  • 1
  • 4
1
vote
1 answer

Limit image's max-height which depends on its sibling's height

How could I limit an image's maximum height so it would be the same as its sibling's height regardless of screen size. The result which is acceptable => Same height - √ A result which isn't acceptable since image column height exceeds its sibling's…
Gugols
  • 63
  • 1
  • 9
1
vote
1 answer

How to put a responsive Object fit cover, on the image Card from the Boostrap 4?

This css took out the responsive layout of the Cards from the Boostrap 4. How can i put a object-fit: cover; on the image of the Card, and have the responsive layout from the Bootstrap 4? #imgUNcover { width: 285px; height: 145px; …
Susi
  • 153
  • 1
  • 3
  • 11
1
vote
2 answers

CSS: how to display an image object-fit:cover in a responsive 50% width context?

I'm working on a profile-kind-of template – half the page (class="actor-info") should show scrollable text and info about a person and the other half should be filled by the person's portrait picture. The picture should always fill half of the…
tillinberlin
  • 429
  • 4
  • 14