I’m facing a need to have a “cover” background on one of the elements.
What are pros and cons of using CSS background-size: cover
vs actual img
with object-fit: cover
?
I’m facing a need to have a “cover” background on one of the elements.
What are pros and cons of using CSS background-size: cover
vs actual img
with object-fit: cover
?
In addition to what others have said about compatibility (background-size: cover
is supported on all modern browsers, where object-fit: cover
is not), a potentially unwanted side-effect of using a div
element with background-size: cover
is that if the user tries to print your page, a lot of times the image won't be printed as it will be deemed a background by the browser and ignored.
That might not matter to you at all, but it is something to be aware of.
There are some ways to get around this, but I don't know of a single, cross-browser silver bullet method.