Created
July 9, 2013 19:24
-
-
Save DomenicoColandrea86/5960430 to your computer and use it in GitHub Desktop.
SASS resolution media query mixin
This file contains hidden or 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
| section { | |
| // only include 1x size image for 'non-retina' screens | |
| @include if-max-resolution(1.49) { | |
| background-image: url('img/section-anchor@1x.png'); | |
| } | |
| // only include 2x size image for 'retina' screens | |
| @include if-min-resolution(1.5) { | |
| background-image: url('img/section-anchor@2x.png'); | |
| background-size: 10.5625rem 1.5625rem; | |
| } | |
| } |
This file contains hidden or 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
| @mixin if-min-resolution($dppx) { | |
| @include if-resolution(min, $dppx) { | |
| @content; | |
| } | |
| } | |
| @mixin if-max-resolution($dppx) { | |
| @include if-resolution(max, $dppx) { | |
| @content; | |
| } | |
| } | |
| @mixin if-resolution($prefix, $dppx) { | |
| // 1px = 96dpi | |
| $dpi: $dppx * 96; | |
| @media | |
| (-webkit-#{$prefix}-device-pixel-ratio: #{$dppx}), | |
| ( #{$prefix}--moz-device-pixel-ratio: #{$dppx}), | |
| ( -o-#{$prefix}-device-pixel-ratio: #{$dppx*2}/2), | |
| ( #{$prefix}-device-pixel-ratio: #{$dppx}), | |
| ( #{$prefix}-resolution: #{$dpi}dpi), | |
| ( #{$prefix}-resolution: #{$dppx}dppx) { | |
| @content; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment