Skip to content

Instantly share code, notes, and snippets.

@pablolobos
Created February 19, 2014 14:29
Show Gist options
  • Save pablolobos/9093199 to your computer and use it in GitHub Desktop.
Save pablolobos/9093199 to your computer and use it in GitHub Desktop.
sass_svg-background-with-png-fallback.scss
$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});
}
}
}
//Usage
body {
@include background-image('pattern');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment