DEV Community

Discussion on: Share your CSS knowledge

Collapse
 
jamesthomson profile image
James Thomson

object-fit is one I haven't used too much until recently (due to browser support). Once you can finally get off that IE11 train the web world really opens up!

developer.mozilla.org/en-US/docs/W...

Collapse
 
saurabhcodeword profile image
Saurabh

isn't is similar to background cover?

Collapse
 
jamesthomson profile image
James Thomson

Indeed it is, but can be used on replaced elements, such as image and video

Collapse
 
markmercier profile image
Mark

My favorite thing about object-fit is that you can use it with img srcset for responsive background images! The picture element is cool if you really need to be serving differently cropped images, but whenever I can get away with same aspect ratio and not supporting IE, I always use object-fit + srcset for all background images.

Collapse
 
jamesthomson profile image
James Thomson

Definitely a good use case! Did this myself in a recent project in fact.

Collapse
 
cwelewa profile image
Clinton Welewa

This property comes in handy when using the img selector, it could be responsive very good one tho!.