【问题标题】:How to change the RGB value of a variable in to string in SASS?如何将变量的RGB值更改为SASS中的字符串?
【发布时间】:2022-01-26 10:01:35
【问题描述】:

我一直在尝试将变量的值更改为字符串,我已经阅读并尝试了一些内置的 SASS 函数。例如看下面的代码:

$primary-color: rgb(0, 0, 0);
$string: quote($primary-color); // => "#000000"

// But I want to have it as "rgb(0, 0, 0)".

谢谢

【问题讨论】:

    标签: string sass rgb tostring


    【解决方案1】:

    $primary-color 变量被 SASS 称为颜色类型,不会保存其格式。 通过使用插值 (#{}) 和 sass:color 模块可以达到目标。有关它们的更多信息,请访问以下链接:

    https://sass-lang.com/documentation/interpolation

    https://sass-lang.com/documentation/modules/color#red

    在下面的代码中,#{}之间的语句是一个SASS代码,会被SASS处理。 red() 是一个获取颜色的红色部分编号的函数; green()blue() 的颜色也与 red() 函数相同。

    $string: "rgb(#{red($primary-color)},#{green($primary-color)},#{blue($primary-color)})"; // => "rgb(0, 0, 0)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多