Last active
September 7, 2016 15:42
-
-
Save rbndelrio/e20d44b80045a59606e4e0227624dfb0 to your computer and use it in GitHub Desktop.
High-dpi images
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 hidpi { | |
@media only screen and (-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2), (min-resolution: 2dppx) { | |
@content; | |
} | |
} | |
@mixin image2x($name, $extension: 'jpg', $size: auto, $position: null, $repeat: null) { | |
@if $size != auto { | |
background-size: $size; | |
} | |
@if $repeat != null { | |
background-repeat: $repeat; | |
} | |
@if $position != null { | |
background-position: $position; | |
} | |
background-image: url('../images/#{$name}.#{$extension}'); | |
@include hidpi { | |
background-image: url('../images/#{$name}@2x.#{$extension}'); | |
} | |
} | |
// Usage: | |
.icon--play { | |
@include image2x('icon--play', 'png', contain); | |
} |
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
<!-- Any device that could possibly have a high-density display will support srcset --> | |
<!-- http://caniuse.com/#feat=srcset --> | |
<img alt="Important image oh man" | |
src="/img/some_image.jpg" | |
srcset="/img/some_image.jpg 1x, /img/[email protected] 2x" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment