Skip to content

Instantly share code, notes, and snippets.

@tylerpaige
Last active January 25, 2017 22:41
Show Gist options
  • Save tylerpaige/023b9de0c9e6635828054b1b108a1777 to your computer and use it in GitHub Desktop.
Save tylerpaige/023b9de0c9e6635828054b1b108a1777 to your computer and use it in GitHub Desktop.
Sass function: Given a list of colors, generates an evenly spaced striped gradient
@function stripes($list) {
$value : ();
@for $i from 1 through length($list) {
$color : nth($list, $i);
$start : 100% / length($list) * ($i - 1);
$end : 100% / length($list) * $i;
$rampSegment : $color $start, $color $end;
$value : append($value, $rampSegment, comma);
}
@return linear-gradient($value);
}
/*
EXMAPLE:
$colors : red, green, blue;
section {
background-image: stripes($colors);
}
OUTPUT:
section {
background-image: linear-gradient(red 0%, red 33.33333%, green 33.33333%, green 66.66667%, blue 66.66667%, blue 100%);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment