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
1 answer

Make an image scales to maintain its aspect ratio while fitting within a flexbox

Considering the following code: * { box-sizing: border-box; margin: 0; } .container { display: flex; flex-direction: column; align-items: stretch; width: 400px; height: 200px; padding: 10px; background:…
rocambille
  • 15,398
  • 12
  • 50
  • 68
0
votes
1 answer

Can we create something like Object-fit: fill in Javascript/Jquery

I'm using object-fit for video. I saw isn't working in IE and some other browsers. Is it possible to create something like Object-fit: fill works with Javascript/Jquery?
NonSmart
  • 1
  • 2
0
votes
1 answer

How to place cover div onto object fit images in responsive flex container?

Here is my demo to show what I mean: * { box-sizing: border-box; } body, html { height: 100%; width: 100%; } body { background: #333; margin: 0; padding: 0; } .content { display: flex; height: 100%; …
ans777
  • 436
  • 5
  • 13
0
votes
0 answers

Does codepen solve for responsiveness?

I was struggling a lot with getting my images to fit inside their parent element. In order to ask a better StackOverflow question, I decided to makde a codepen, but when I did that, the issue was solved? it's still not solved when I run a local…
EJW
  • 604
  • 2
  • 10
  • 22
-1
votes
3 answers

How to make the photo fit to its container

here I have a div with a class="container", inside this div there is an img, I want the image to cover all the parent div, whatever size it is, also I want the image to preserve its aspect ratio, and the most important thing is, either width or…
-1
votes
2 answers

how to place a button on a specific image point, the image being displayed as object-fit:cover

So I need to have this image with a ratio lets say 2880x1520 on 100vh. I can do that using object-fit:cover; object-position: center left; It works fine. The problem is that I also have to place buttons on specific parts of the image and the image…
François Richard
  • 6,817
  • 10
  • 43
  • 78
-1
votes
1 answer

Fallback solution for object-fit on flexslider

I am using a flexslider (fixed height of 500px) but have slightly modified it to allow images to display nicely even if they have more than 500px height. Therefore I have added object-fit: cover; object-position: center; to the CSS of the img-Tag.…
tom_lehnert
  • 49
  • 1
  • 7
-2
votes
1 answer

How to crop blank spaces from an image using CSS?

I imported an image to work with on a web project. Turned out that the content of the image is smaller than the image(kind of a blank space all around the content). So, I want to treat this image on my project(using img tag) as though its size was…
1 2 3 4 5 6 7
8