Last active
December 29, 2015 14:09
-
-
Save benbridge/7682344 to your computer and use it in GitHub Desktop.
Javascript SVG detection with CSS 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
# Add below script to html head, before css. | |
<script> | |
function supportsSVG(){if(document.createElementNS&&document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect){return true}}if(supportsSVG()){document.documentElement.className+=" svg"}; | |
</script> | |
# Example scss | |
.svg-bg-image { | |
background: url(_media/image.png) no-repeat; | |
height: 100px; | |
width: 100px; | |
.svg & { | |
background: url(_media/image.svg) no-repeat; | |
background-size: 100px 100px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment