Skip to content

Instantly share code, notes, and snippets.

@kiub
Last active August 29, 2015 14:22
Show Gist options
  • Save kiub/ed8c38dc71b225f87404 to your computer and use it in GitHub Desktop.
Save kiub/ed8c38dc71b225f87404 to your computer and use it in GitHub Desktop.
$alpha_color: red;
$bravo_color: blue;
$charlie_color: green;
$color_names: alpha_color bravo_color charlie_color;
$color_vars: $alpha_color $bravo_color $charlie_color;
@each $name in $color_names {
$i: index($color_names, $name);
%#{$name} {
background: nth($color_vars, $i);
}
}
@each $name in $color_names {
$i: index($color_names, $name);
.#{$name} {
@extend %#{nth($color_names, $i)};
}
}
// Refactor with @for loop
@for $i from 1 through length($color_names) {
%#{nth($color_names, $i)} {
color: nth($color_vars, $i);
}
}
@for $i from 1 through length($color_names) {
.#{nth($color_names, $i)} {
@extend %#{nth($color_names, $i)};
}
}
// result
//.alpha_color {
// background: red;
//}
//.bravo_color {
// background: blue;
//}
//.charlie_color {
// background: green;
//}
//.alpha_color {
// color: red;
//}
//.bravo_color {
// color: blue;
//}
//.charlie_color {
// color: green;
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment