【问题标题】:SASS Maps: Can I export the contents as CSS properties?SASS Maps:我可以将内容导出为 CSS 属性吗?
【发布时间】:2020-03-26 10:10:53
【问题描述】:

我正在尝试找到从函数中输出多个颜色值的最有效方法。该函数(最终将)采用基色并使用 sass 函数输出配色方案(想想互补、三级、单色等)。

这是我产生错误的代码

background-color: #020633, color:b7bced 不是有效的 CSS 值

我确定我需要用分号替换逗号,我只是不确定我是否可以或者我是否正确地处理这个问题。

$base-color: #0a104e;

@function darkest-color($darkest-base-color-bg) {
    //figure the backgound
    $darkest-bg-color: scale-color($darkest-base-color-bg, $saturation: 66%, $lightness: -40%, $alpha: 100%);
    //figure the text
    $darkest-text-color-nocontrast: scale-color($darkest-base-color-bg, $saturation: 66%, $lightness: 40%, $alpha: 100%);
    //figure the contrast between the background and the text
    $darkest-text-color: color_adjust_contrast_AERT($darkest-text-color-nocontrast, $darkest-base-color-bg);
    //add the two colors to a map
    $darkest-color: '';
    @return $darkest-color (background-color: $darkest-bg-color, color:$darkest-text-color, );
}

.darkest-accent-strip {
    content: darkest-color($base-color);
}

【问题讨论】:

    标签: css sass sass-maps


    【解决方案1】:

    你不能将函数导出为属性,但你可以使用 mixins 来实现你想要的。您可以阅读有关Sass Mixins 的更多信息。我在这里做了你想要的

    $base-color: #0a104e;
    
    @mixin darkest-color($darkest-base-color-bg) {
        $darkest-bg-color: scale-color($darkest-base-color-bg, $saturation: 66%, $lightness: -40%, $alpha: 100%);
        $darkest-text-color-nocontrast: scale-color($darkest-base-color-bg, $saturation: 66%, $lightness: 40%, $alpha: 100%);
        $darkest-text-color: color_adjust_contrast_AERT($darkest-text-color-nocontrast, $darkest-base-color-bg);
    
        background-color: $darkest-bg-color;
        color: $darkest-text-color;
    }
    
    .darkest-accent-strip {
        @include darkest-color($base-color);
    }
    

    【讨论】:

    • 谢谢。我在想我做错了。这比使用函数更有意义,因为我现在考虑它并在代码中看到它。
    猜你喜欢
    • 2011-11-01
    • 2022-01-12
    • 2015-03-10
    • 1970-01-01
    • 2022-11-24
    • 2022-03-17
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多