img {
width: 200px;
height: 150px;
object-fit: cover;
}
<img src="https://res.cloudinary.com/wisdo/image/upload/v1589582065/mentored-sessions/New/Kim.jpg" />
Many other images work fine. In other browsers everything also works as expected.
What can be the problem?
Chrome Version 84.0.4147.89
It's because the image itself is saved incorrectly or malformed in someway.
I noticed this when I downloaded the original image to my computer, the preview was showing horizontal despite the image dimensions being in portrait orientation (2208 x 2944).
I opened it in Preview rotated it back to what it should be and saved it. I put it up on imgur to grab a link to use:
Edit for further explanation based on comments from @dgknca:
As @dgknca pointed out,
background-position: cover
works because the image in this case is not a replaced element, rather the browser gets the image as presented and uses it as a background imageobject-fit
works on replaced elements such asvideo, img, iframe and embed
(being the most common).So, in this particular case, it appears that the meta data or other data associated with the actual image was corrupt/malformed/incorrect. So when Chrome interpreted the actual image data for this replaced element, it was trying to do
object-fit: cover
- to Chrome the image was horizontal and not vertical, so it was being stretched or rather "fit" incorrectly.The link to the MDN article about replaced elelemts:
https://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_element
Here's the imporant part: