Created
October 14, 2015 07:03
-
-
Save JoeNoPhoto/da172f75179f0669160f to your computer and use it in GitHub Desktop.
SVG background images with PNG and retina 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
$image-path: '../img' !default; | |
$fallback-extension: 'png' !default; | |
$retina-suffix: '@2x'; | |
@mixin background-image($name, $size:false){ | |
background-image: url(#{$image-path}/#{$name}.svg); | |
@if($size){ | |
background-size: $size; | |
} | |
.no-svg &{ | |
background-image: url(#{$image-path}/#{$name}.#{$fallback-extension}); | |
@media only screen and (-moz-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { | |
background-image: url(#{$image-path}/#{$name}#{$retina-suffix}.#{$fallback-extension}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pattern.svg
pattern.png
pattern@2x.png
Usage