Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase color saturation with sass mixin

Tags:

css

sass

mixins

I'm trying to write looped mixin that iteratively increases the saturation of a background-color. Here's the latest mixin code:

@mixin generateBackgroundSteps($cell-count, $color) {
    @for $i from 0 through $cell-count - 1 {
        $percent: (5 * $i) + "%";
        $new-color: saturate($color, $percent);

        &[setting-id="#{$i}"] {
            background-color: $new-color;                
        }
    }
}

No matter how I've altered this, the produced css just keeps looking like this:

.rubric-design .rubric .create-new-criteria .create-criteria-initial-
settings .create-criteria-setting[setting-id="2"] {
      background-color: saturate(#90afc8);
}

Maybe it's the way I'm forming $percent. It must be something obvious!

like image 581
webhound Avatar asked Dec 08 '25 11:12

webhound


1 Answers

Try using percentage function.

percentage function in SCSS

$percent: percentage((5 * $i) / (5 * $cell-count));

@mixin generateBackgroundSteps($cell-count, $color) {
@for $i from 0 through $cell-count - 1 {
    $percent: percentage((5 * $i) / (5 *$cell-count));
    $new-color: saturate($color, $percent);

    &[setting-id="#{$i}"] {
        background-color: $new-color;                
    }
 }
}
like image 172
Yogen Darji Avatar answered Dec 11 '25 02:12

Yogen Darji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!