Skip to content

Instantly share code, notes, and snippets.

@JonCatmull
Last active December 21, 2016 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCatmull/09cac384f1c5f8943cc0 to your computer and use it in GitHub Desktop.
Save JonCatmull/09cac384f1c5f8943cc0 to your computer and use it in GitHub Desktop.
Create a responsive sprite map with support for svg and png. Uses modernizer for png fallback.
@mixin responsive-sprite($img, $icon-classes, $horizontal: true) {
$icon-number: ceil(length($icon-classes));
$moveby: 100% / ($icon-number - 1); // one less that actual amount
background-image: url('#{$img}');
background-position: 0 0;
background-repeat: no-repeat;
@if $horizontal {
background-size: ($icon-number * 100%) 100%;
} @else {
background-size: 100% ($icon-number * 100%);
}
@each $icon in $icon-classes {
$i: index($icon-classes, $icon);
&.#{$icon} {
background-position: ($moveby * ($i - 1)) 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment