【问题标题】:Increase color saturation with sass mixin使用 sass mixin 增加颜色饱和度
【发布时间】:2017-12-26 05:57:44
【问题描述】:

我正在尝试编写循环混合来迭代地增加背景颜色的饱和度。这是最新的 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);
}

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

【问题讨论】:

    标签: css sass mixins


    【解决方案1】:

    尝试使用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;                
        }
     }
    }
    

    【讨论】:

    • 这完全有效。谢谢!我稍微修改为$percent: percentage((10 * $i) / 100);
    • @webhound 太棒了!
    猜你喜欢
    • 2016-09-25
    • 2011-05-17
    • 2012-11-28
    • 1970-01-01
    • 2023-03-25
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多