Last active
December 21, 2016 10:20
-
-
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.
This file contains 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 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