Skip to content

Instantly share code, notes, and snippets.

@dcalhoun
Last active August 29, 2015 13:56
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 dcalhoun/2da26ec6dd0f8ff1764f to your computer and use it in GitHub Desktop.
Save dcalhoun/2da26ec6dd0f8ff1764f to your computer and use it in GitHub Desktop.
Custom icons loop.
// Position icon background image
@mixin icon($index, $y: 0, $width: 80px) {
background-position: #{($index * -$width)} $y;
}
$icon: users, megaphone, gavel, warning, chat, faq, pen-paper, document,
pdf, checklist, scale, charts, calendar, search, mail, scroll,
scroll-44, info, url;
.bopr-icon {
background: image-url('bopr-icons.png') no-repeat 0 0;
display: inline-block;
height: 80px;
width: 80px;
@include hidpi(2) {
background-image: image-url('bopr-icons_2x.png');
background-size: auto 160px;
}
// Loop through icon names to build backgrounds
@for $i from 1 through length($icon) {
$index: $i - 1; // Pseudo zero-based index
$class: nth($icon, $i); // Icon name
&.#{$class} {
@include icon($index); // Output background-position
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment