使用sass mixin增加色彩饱和度

时间:2017-07-20 13:35:30

标签: css sass mixins

我试图编写循环mixin,迭代地增加背景颜色的饱和度。这是最新的mixin代码:

@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;                
        }
    }
}

无论我如何改变这一点,所产生的css仍然看起来像这样:

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

也许这就是我形成百分之百的方式。它一定是明显的东西!

1 个答案:

答案 0 :(得分:3)

尝试使用percentage功能。

SCSS中的

percentage功能

$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;                
    }
 }
}