Skip to content

Instantly share code, notes, and snippets.

@oklai
Created May 7, 2014 06:29
Show Gist options
  • Save oklai/9897c602bfd57f70ddc6 to your computer and use it in GitHub Desktop.
Save oklai/9897c602bfd57f70ddc6 to your computer and use it in GitHub Desktop.
Retina sprite for Compass
@import "compass/utilities/sprites"; // Include compass sprite helpers
@import "compass/css3/background-size"; // Include helper to calc background size
// background sprite for retina
// Use:
// $sprites2x: sprite-map("sprites/*.png", $spacing: 2px);
// .icon-new {
// @include retina-sprite(icon-new, $sprites2x);
// }
@mixin retina-sprite($name, $sprites2x, $padding: 0) {
background-repeat: no-repeat;
@if $padding > 0 {
padding: $padding;
}
$pos: sprite-position($sprites2x, $name, -$padding * 2, -$padding * 2);
background-image: sprite-url($sprites2x);
background-position: nth($pos, 1) nth($pos, 2) / 2;
@include background-size(ceil(image-width(sprite-path($sprites2x)) / 2) auto);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment