-
-
Save iansoper/1565894 to your computer and use it in GitHub Desktop.
PE to use SVG as CSS background image with fallback for IE8/7/6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PE to use SVG as CSS background image with fallback for IE8/7/6 | |
* | |
* Using SVG as CSS background image to display | |
* resolution-independent logos or icons is pretty | |
* awesome but does completely fail on IE8/7/6 | |
* | |
* The trick: | |
* All three IE versions don't support rgba color values. | |
* By defining a rgba background color together with the | |
* SVG background image for all modern browsers, IEs prior | |
* to IE 9 will automatically ignore that and switch to the | |
* first background definition, where you can add a fallback | |
* png with the same size for example. | |
* | |
* Tested in: | |
* Safari 5.1+ | |
* Chrome 16 | |
* Firefox 9+ | |
* Opera 11.6+ | |
* MobileSafari on iOS 5 | |
* IE6, IE7, IE8, IE9 | |
* | |
* General support for SVG backgrounds: | |
* http://caniuse.com/#feat=svg-css | |
* | |
* Known issues: | |
* - Does not work in Firefox < 4 | |
* - Might not work on older versions of Android Browser | |
* | |
* Thoughts? | |
* Please reply on Twitter: @bastianallgeier | |
* Or comment on this gist on Github. | |
* | |
* Awesome mod by @jng5 to demonstrate the resizability: | |
* http://dabblet.com/gist/1564480 | |
* | |
*/ | |
body { | |
background: #fff; | |
} | |
.twitter-logo { | |
width: 200px; | |
height: 200px; | |
text-indent: -6000px; | |
background: url(http://cl.ly/D4xT/twitter_newbird_blue.png) no-repeat center center; | |
background: rgba(0,0,0,0) url(http://cl.ly/D4o5/twitter_newbird_blue.svg) no-repeat center center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- content to be placed inside <body>…</body> --> | |
<div class="twitter-logo">Twitter Birdy</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"view":"split-vertical","prefixfree":"1","page":"css"} |
With this, both images will be downloaded for all browsers even if only one of them is used?
I like your solution, very similar to the using of multiple backgrounds to ensure the right type is downloaded.
Unfortunately this fails miserably on Android 2.3 which is still a large proportion of many websites customer base. As of right now I cannot find a workaround or a good solution that supports Android 2.3 well enough. The Android market is just too fragmented to be confident enough to apply this and accept the fallback of nothing showing for them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is awesome. thanks for sharing!