CSS Object Fit for Internet Explorer

10 Apr 2019

Here’s a nice polyfill by Federico Brigante for the object-fit property which is not natively supported by Internet Explorer.

HTML:

<script src="ofi.min.js"></script>
<img class='img-fit ' src='image.jpg'>

CSS:

.img-fit     {
	object-fit: contain;
    /* font-family necessary for IE */
	font-family: 'object-fit: contain;';
}

JavaScript:

//when content loaded
objectFitImages();