Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Last active December 16, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2ndkauboy/5397443 to your computer and use it in GitHub Desktop.
Save 2ndkauboy/5397443 to your computer and use it in GitHub Desktop.
A simple mixin to use a different background images for HiDPI devices.
@mixin background-image-hidpi($normalImage, $hdpiImage, $ratio){
// normal image
background-image: url('#{$normalImage}');
// high dpi image
@include pixel-ratio($ratio){
background-image: url('#{$hdpiImage}');
}
}
// This mixin uses the mixin pixel-ratio() which you can find in anoter gist: https://gist.github.com/2ndkauboy/5397402
@mixin pixel-ratio($ratio){
@media (-webkit-min-device-pixel-ratio: $ratio), (min--moz-device-pixel-ratio: $ratio), (min-resolution: #{$ratio}dppx), (min-resolution: #{$ratio * 96}dpi){
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment