Last active
January 3, 2016 17:29
-
-
Save atelierbram/8496272 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
body { | |
background-image: url(../img/pattern.svg); | |
} | |
.no-svg body { | |
background-image: url(../img/pattern.png); | |
} | |
@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) { | |
.no-svg body { | |
background-image: url(../img/pattern@2x.png); | |
} | |
} |
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
// ---- | |
// Sass (v3.3.0.rc.2) | |
// Compass (v1.0.0.alpha.17) | |
// ---- | |
/* | |
* http://zerosixthree.se/8-sass-mixins-you-must-have-in-your-toolbox/ | |
This mixin depends on Modernizr and creates a bit more work for you when creating images for your site, but it’s really worth it in the end. | |
You need one .svg file, that will serve as the default background image. You’ll also need a regular .png that serves as a fallback for non-svg-supporting browsers. And last you need a twice as large .png as a second fallback to retina screens. | |
All in all you need this: | |
* pattern.svg | |
* pattern.png | |
* pattern@2x.png | |
*/ | |
$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}); | |
} | |
} | |
} | |
// example of usage | |
body { | |
@include background-image('pattern'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment