# SCSS 颜色属性变量的烦恼

**URL:** <https://meta.discourse.org/t/scss-color-property-variable-headaches/278711>\
**Category:** Development\
**Created:** [2023 年9 月 12 日 12:37 UTC](https://meta.discourse.org/t/scss-color-property-variable-headaches/278711 "2023-09-12T12:37:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

作者： ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
发布日期： [2023 年9 月 12 日 13:20 UTC](https://meta.discourse.org/t/scss-color-property-variable-headaches/278711/4 "2023-09-12T13:20:07Z")

</div>

嗨 Lilly！

我最近也遇到了同样的问题。😄

简短回答：主题和 CSS 变量被视为字符串，虽然您可以在 `color`、`background`、`border` 等属性中使用它们，但不能在 SCSS 颜色函数中使用它们。

该问题与 Discourse 无关：

> <https://github.com/sass/sass/issues/3006>
>
> I am passing in variables to sass using gulp-sass-variables, which will always i…nject a string.
> 
> Unquote doesn't seem to have any effect on my string.
> 
> \`\`\`
> $primary: "#ffffff"; // \<- Passed in via gulp-sass-variables
> 
> $anchor: scale-color(unquote($primary), $lightness: -14%); // Error: $color: #ffffff is not a color.
> \`\`\`
> 
> Am I using unquote in the wrong way?

有一个过于复杂的方法可以规避这个问题，我没有尝试过：[Unquote not working on colour string · Issue #3006 · sass/sass · GitHub](https://github.com/sass/sass/issues/3006#issuecomment-798800454)

---

_[View the full topic](https://meta.discourse.org/t/scss-color-property-variable-headaches/278711)._
