Skip to content

Instantly share code, notes, and snippets.

@nex3
Last active June 13, 2024 20:25
Show Gist options
  • Save nex3/d54ba9ffefb74e00e1e86959b6f99d5b to your computer and use it in GitHub Desktop.
Save nex3/d54ba9ffefb74e00e1e86959b6f99d5b to your computer and use it in GitHub Desktop.
@use 'sass:color';
@use 'sass:list';
@use 'sass:math';
$start: red;
$end: blue;
@function gradient($space, $stops: 20) {
$stops-list: ($start 0%,);
@for $i from 1 through $stops {
$percentage: math.div(100% * $i, ($stops + 1));
$color: color.mix($start, $end, 100% - $percentage, $space);
$stops-list: list.join($stops-list, ($color $percentage,));
}
@return linear-gradient(90deg, $stops-list, $end 100%);
}
.gradient {
width: 100%;
height: 100px;
color: white;
font-family: sans-serif;
font-weight: bold;
padding: 10px;
box-sizing: border-box;
margin-bottom: 5px;
@each $space in srgb, srgb-linear, xyz-d50, xyz-d65, lab, lch, oklab, oklch {
&.#{$space} {
background: gradient($space);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment