Created
October 23, 2012 15:10
-
-
Save borismus/3939311 to your computer and use it in GitHub Desktop.
High DPI CSS image backgrounds with robust fallbacks
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
compass-image-set(W, H, IMG1, BP1, IMG2, BP2, ..., IMG_N, BP_N) | |
/** Default fallback */ | |
sel { | |
background-image: url($IMG1); | |
background-size: $W, $H; | |
} | |
/* First pixel ratio breakpoint */ | |
@media | |
(min--moz-device-pixel-ratio: $BP2), | |
(-o-min-device-pixel-ratio: $BP2), | |
(-webkit-min-device-pixel-ratio: $BP2), | |
(min-device-pixel-ratio: $BP2) { | |
sel { | |
background: url($IMG2); | |
} | |
} | |
/* Second pixel ratio breakpoint */ | |
@media | |
(min--moz-device-pixel-ratio: $BP3), | |
(-o-min-device-pixel-ratio: $BP3), | |
(-webkit-min-device-pixel-ratio: $BP3), | |
(min-device-pixel-ratio: $BP3) { | |
sel { | |
background: url($IMG3); | |
} | |
} | |
/* More breakpoints if needed */ | |
/* The new image-set way */ | |
sel { | |
background-image: -webkit-image-set( | |
url($IMG1) ${BP1}x, | |
url($IMG2) ${BP2}x, | |
url($IMG3) ${BP3}x | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment