Skip to content

Instantly share code, notes, and snippets.

@derekblank
Last active December 17, 2015 10:09
Show Gist options
  • Save derekblank/5592610 to your computer and use it in GitHub Desktop.
Save derekblank/5592610 to your computer and use it in GitHub Desktop.
Sass @each loop examples
// Standard loop
@each $item in web, design, strategy, development, video, marketing {
&#wwd-#{$item} {
background-image: url('bg-wwd-#{$item}.jpg');
}
}
// Multi-dimensional loop
a {
background: image-url('icons/social-media-sprite.png') no-repeat;
display: block;
height: 15px;
width: 15px;
@include hide-text;
$network-sprite-map: facebook 5px 0, twitter -26px 0, instagram -57px 0, youtube -87px 0;
@each $pair in $network-sprite-map {
&.#{nth($pair, 1)}-icon {
background-position: #{nth($pair, 2)} #{nth($pair, 3)};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment