Skip to content

Instantly share code, notes, and snippets.

@benbridge
Last active December 29, 2015 14:09
Show Gist options
  • Save benbridge/7682344 to your computer and use it in GitHub Desktop.
Save benbridge/7682344 to your computer and use it in GitHub Desktop.
Javascript SVG detection with CSS fallback.
# 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