Skip to content

Instantly share code, notes, and snippets.

@hayatbiralem
Created April 17, 2014 12:55
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 hayatbiralem/10981215 to your computer and use it in GitHub Desktop.
Save hayatbiralem/10981215 to your computer and use it in GitHub Desktop.
Make class list for collection in Sass
$facebook-color : hsla(222, 47%, 40%, 1); // #365397
$twitter-color : hsla(198, 100%, 47%, 1); // #00a9f1
$linkedin-color : hsla(203, 100%, 35%, 1); // #006db3
social-platforms: facebook $facebook-color,
twitter $twitter-color,
linkedin $linkedin-color;
@mixin make-class-list-for-collection($collection, $index: 1, $prefix: "") {
$list: "";
@each $item in $collection {
@if($prefix == ""){
@if ($list == ""){
$list: ".#{nth($item, $index)}";
} @else {
$list: "#{$list}, .#{nth($item, $index)}";
}
}
@else {
@if ($list == ""){
$list: ".#{$prefix}#{nth($item, $index)}";
} @else {
$list: "#{$list}, .#{$prefix}#{nth($item, $index)}";
}
}
}
#{$list} {
@content;
}
}
@include make-class-for-collection($social-platforms, 1, s-) {
display: block;
&:hover {
color: #fc0;
background-color: #fff;
}
}
// Output:
//
// .s-facebook, .s-twitter, .s-linkedin { display: block; }
// .s-facebook:hover, .s-twitter:hover, .s-linkedin:hover { color: #fc0; background-color: #fff; }
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment