Adds support for background-size "cover" and "contain" to IE8
See the codeAn IE behavior adding support for background-size to IE8.
Progressive Enhancement is the mantra I live by. It means "Have fun with CSS3 and don't worry about IE8 users; they'll never notice they're missing out on your gorgeous text-shadows and gradients, anyway".
All was well until I discovered the elegance of background-size: cover; and background-size: contain;.
The first one, for instance, allows an image to completely cover a background,
without having to send a 1920x1080 background image down the pipes.
Unfortunately, they don't degrade gracefully: websites would likely appear broken to IE8 users :-( ...unless you use this behavior!
Upload backgroundsize.min.htc to your website, along with the .htaccess that will send the mime-type required by IE (Apache only — it's built in nginx, node and IIS).
Everywhere you use background-size in your CSS, add a reference to this file.
.selector {
background-size: cover;
/* The url is relative to the document, not to the css file! */
/* Prefer absolute urls to avoid confusion. */
-ms-behavior: url(/backgroundsize.min.htc);
}
The elements styled this way should have a position: relative; or position: fixed; and a z-index.
If not, they will be given a position: relative; and z-index: 0;.
This polyfill inserts an <img/> in the background of all elements matched in the css to emulate the background-size value.
Calculating the displayed position and size of this image is quite complex and function of numerous parameters:
It is thus impossible to emulate background-size completely and perfectly. But it's still possible to enjoy the main features:
The following style properties, values or behavior aren't supported:
background-positionrepeat value in background-repeatRemoving any of these limitations is probably just one fork away...
MIT Licensed http://louisremi.mit-license.org/ Early versions by @louis_remi, now maintained by @jefferyto
Are you using this in a paid work?
Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
none (#13)background-attachment: fixed for body (#22)left or top for background-position (#14, #21, #24)NaN JS errors (#11, #16, #23)970 followers · starred May 2014
2,409 followers · starred Jul 2013
408 followers · starred Jun 2013
190 followers · starred Apr 2014
Adds support for background-size "cover" and "contain" to IE8
See the codeAn IE behavior adding support for background-size to IE8.
Progressive Enhancement is the mantra I live by. It means "Have fun with CSS3 and don't worry about IE8 users; they'll never notice they're missing out on your gorgeous text-shadows and gradients, anyway".
All was well until I discovered the elegance of background-size: cover; and background-size: contain;.
The first one, for instance, allows an image to completely cover a background,
without having to send a 1920x1080 background image down the pipes.
Unfortunately, they don't degrade gracefully: websites would likely appear broken to IE8 users :-( ...unless you use this behavior!
Upload backgroundsize.min.htc to your website, along with the .htaccess that will send the mime-type required by IE (Apache only — it's built in nginx, node and IIS).
Everywhere you use background-size in your CSS, add a reference to this file.
.selector {
background-size: cover;
/* The url is relative to the document, not to the css file! */
/* Prefer absolute urls to avoid confusion. */
-ms-behavior: url(/backgroundsize.min.htc);
}
The elements styled this way should have a position: relative; or position: fixed; and a z-index.
If not, they will be given a position: relative; and z-index: 0;.
This polyfill inserts an <img/> in the background of all elements matched in the css to emulate the background-size value.
Calculating the displayed position and size of this image is quite complex and function of numerous parameters:
It is thus impossible to emulate background-size completely and perfectly. But it's still possible to enjoy the main features:
The following style properties, values or behavior aren't supported:
background-positionrepeat value in background-repeatRemoving any of these limitations is probably just one fork away...
MIT Licensed http://louisremi.mit-license.org/ Early versions by @louis_remi, now maintained by @jefferyto
Are you using this in a paid work?
Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
none (#13)background-attachment: fixed for body (#22)left or top for background-position (#14, #21, #24)NaN JS errors (#11, #16, #23)970 followers · starred May 2014
2,409 followers · starred Jul 2013
408 followers · starred Jun 2013
190 followers · starred Apr 2014