css - 使用 sass mixin 增加色彩饱和度

标签 css sass mixins

我正在尝试编写循环混合,以迭代方式增加背景颜色的饱和度。这是最新的混合代码:

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

也许这就是我形成 $percent 的方式。这一定很明显!

最佳答案

尝试使用 percentage 函数。

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

关于css - 使用 sass mixin 增加色彩饱和度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45216364/

相关文章:

css - Sass 扩展和父选择器

sass - 如何使 Susy Sass 位置正常工作并将元素与中心列对齐

javascript - 有没有办法将 Proxy 对象绑定(bind)到 ES6 类构造函数?

css - 供应商特定属性的 SCSS 混合

html - "x Of y"样式css,中间分隔符,垂直居中对齐

javascript - 在 jQuery 上将动画放慢到结束

php - 尝试添加联系表

css - 背景颜色不覆盖完全定义的背景属性

css - SCSS 对 VS 代码的自动建议

css - Less 中基于变量的 Mixin 守卫