Skip to content

Instantly share code, notes, and snippets.

@renestalder
Forked from thulstrup/compass-retina-sprites.scss
Last active December 15, 2015 09:09
Show Gist options
  • Save renestalder/5236136 to your computer and use it in GitHub Desktop.
Save renestalder/5236136 to your computer and use it in GitHub Desktop.
@import "compass/css3/background-size";
// $sprites: sprite-map("../images/sprite/normal/*.png");
// $sprites-retina: sprite-map("../images/sprite/retina/*.png");
// $sprite-width: 363px;
@mixin sprite-background($name) {
$sprite-url: sprite-url($sprites);
$sprites-retina-url: sprite-url($sprites-retina);
background-image: url(sprite-path($sprites));
background-position: sprite-position($sprites, $name);
background-repeat: no-repeat;
display: block;
height: image-height(sprite-file($sprites, $name));
width: image-width(sprite-file($sprites, $name));
@media (-webkit-min-device-pixel-ratio: 2), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 2) {
// Workaround for https://gist.github.com/2140082
@if (sprite-position($sprites, $name) != sprite-position($sprites-retina, $name)) {
$ypos: round(nth(sprite-position($sprites-retina, $name), 2) / 2);
background-position: 0 $ypos;
}
// Hard coded width of the normal sprite image. There must be a smarter way to do this.
@include background-size($sprite-width auto);
background-image: url(sprite-path($sprites-retina));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment