Skip to content

Instantly share code, notes, and snippets.

@erickreutz
Last active December 18, 2015 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickreutz/5835340 to your computer and use it in GitHub Desktop.
Save erickreutz/5835340 to your computer and use it in GitHub Desktop.
This is a the best method I have found for getting css image sprites working with both retina and non-retina images.
$sprites: sprite-map("icons/*.png", $spacing: 2px);
$sprites2x: sprite-map("icons-2x/*.png", $spacing: 2px);
@mixin icon-with-retina($name) {
@include sprite-dimensions($sprites, $name);
background-position: sprite-position($sprites, $name);
@include hidpi(2.0) {
$pos: sprite-position($sprites2x, $name);
background-position: nth($pos, 1) / 2 nth($pos, 2) / 2;
@include background-size(ceil(image-width(sprite-path($sprites2x)) / 2) auto);
}
}
[class*="icon"] {
background-image: inline-sprite($sprites);
background-repeat: no-repeat;
display: inline-block;
@include hidpi(2.0) {
background-image: inline-sprite($sprites2x);
}
}
.icon-flickr { @include icon-with-retina(flickr); }
.icon-dribbble { @include icon-with-retina(dribbble); }
.icon-twitter { @include icon-with-retina(twitter); }
.icon-pinterest { @include icon-with-retina(pinterest); }
.icon-reblog-white { @include icon-with-retina(reblog-white); }
.icon-fancy { @include icon-with-retina(fancy); }
.icon-reblog-grey { @include icon-with-retina(reblog-grey); }
.icon-reblog-green { @include icon-with-retina(reblog-green); }
.icon-reblog-gloss { @include icon-with-retina(reblog-gloss); }
.icon-reblog-black { @include icon-with-retina(reblog-black); }
.icon-facebook { @include icon-with-retina(facebook); }
.icon-eye-gloss { @include icon-with-retina(eye-gloss); }
.icon-share-black { @include icon-with-retina(share-black); }
.icon-heart-white { @include icon-with-retina(heart-white); }
.icon-book { @include icon-with-retina(book); }
.icon-tag-grey { @include icon-with-retina(tag-grey); }
.icon-plane { @include icon-with-retina(plane); }
.icon-home { @include icon-with-retina(home); }
.icon-heart-red { @include icon-with-retina(heart-red); }
.icon-heart-grey { @include icon-with-retina(heart-grey); }
.icon-heart-gloss { @include icon-with-retina(heart-gloss); }
.icon-heart-black { @include icon-with-retina(heart-black); }
.icon-user { @include icon-with-retina(user); }
.icon-close-black { @include icon-with-retina(close-black); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment