Created
March 12, 2015 18:09
-
-
Save hfknight/b75b82f6d53a6393fa20 to your computer and use it in GitHub Desktop.
SVG Fallback
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
/* using svg as a background-image */ | |
.my-element { | |
background-image: url(image.svg); | |
} | |
.no-svg .my-element { | |
background-image: url(image.png); | |
} | |
.my-element { | |
background-image: url(fallback.png); | |
background-image: | |
linear-gradient(transparent, transparent), | |
url(image.svg); | |
} | |
/* using svg as inline <svg> | |
if using inline <svg> with <use>, try svg4everybody.js to inject svg code to fix IE non-support issue | |
*/ | |
<!-- inline svg --> | |
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"> | |
<switch> | |
<circle cx="20" cy="20" r="18" stroke="grey" stroke-width="2" fill="#99FF66" /> | |
<foreignObject> | |
<div class="nicolas_cage fallback"></div> | |
</foreignObject> | |
</switch> | |
</svg> | |
<!-- external svg --> | |
<object type="image/svg+xml" data="circle_orange.svg"> | |
<div class="nicolas_cage fallback"></div> | |
</object> | |
/* using svg as <img> */ | |
<img src="image.svg" onerror="this.src='image.png'"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment