Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Last active July 9, 2020 06:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elijahmanor/29c80c3f76f7690425e2 to your computer and use it in GitHub Desktop.
Save elijahmanor/29c80c3f76f7690425e2 to your computer and use it in GitHub Desktop.
Dynamic Repeating Sass Colors
$chartColors: #56c7fa, #f76540, #ffcb05, #62cd9f, #b67baa;
@for $i from 1 through length($chartColors) {
$chartColors: append($chartColors, darken(nth($chartColors, $i), 25));
}
$chartColors: #56c7fa, #f76540, #ffcb05, #62cd9f, #b67baa;
@for $i from 1 through length($chartColors) {
$chartColors: append($chartColors, darken(nth($chartColors, $i), 25));
}
$chartColorsLength: length($chartColors);
.color {
@for $i from 1 through $chartColorsLength {
&:nth-of-type(#{$chartColorsLength}n+#{$i}) {
background-color: nth($chartColors, $i);
}
}
}
.color:nth-of-type(10n+1) {
background-color: #56c7fa;
}
.color:nth-of-type(10n+2) {
background-color: #f76540;
}
.color:nth-of-type(10n+3) {
background-color: #ffcb05;
}
/* ... other 10n+# variations ... */
$chartColorsLength: length($chartColors);
.color {
@for $i from 1 through $chartColorsLength {
&:nth-of-type(#{$chartColorsLength}n+#{$i}) {
background-color: nth($chartColors, $i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment