Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS how to fully stretch background image that works in IE?? Re: how to fully stretch background image that works in IE??

#116362
louisremi
Member

In modern browsers you can now use the CSS3 property background-size

.selector {
/* will stretch the image so that it covers all of the element */
background-size: cover;
/* will stretch the image so that it fits perfectly inside the element */
background-size: contain;
}

This allows to achieve background stretching while preserving the aspect ratio of the background-image: https://developer.mozilla.org/en-US/docs/CSS/background-size

I’ve personally developed a polyfill that implements those properties in IE8: https://github.com/louisremi/background-size-polyfill