SASS/SCSS变量可能是可能的吗?

发布于 2025-02-01 01:26:23 字数 848 浏览 3 评论 0原文

当尝试在CSS中显示我声明的SASS变量时,我不会在CSS输出文件中获得变量本身,而是给出了变量的值。

更明确的是,这就是我得到的:

SCS/SASS输入

$gray__background: #2d2d2d;

:root {
    --gray__background: #{$gray__background};
}

body{
  background-color: $gray__background;
}

CSS“输出”

:root {
 --gray__background: #2d2d2d;
}

body{
 background-color: #2d2d2d;
}

这就是我期望获得的:

CSS“输出”

:root {
  --gray__background: #2d2d2d;
}
body{
  background-color: var(--gray__background);
}

短篇小说:我想知道CSS“自动生成的”文件<<代码>背景色:var( - 灰色__background); ,而不是backendy-color:#2d2d2d;可以实现。

我使用 live sass Compiler vscode的扩展。

抱歉,如果我的问题有些模糊。我是新手编码。

When trying to display in CSS the SASS variable that I declared, I don't get the variable itself in the CSS output file, but the value given to the variable.

To be more clear, this is what I get:

SCSS/SASS input

$gray__background: #2d2d2d;

:root {
    --gray__background: #{$gray__background};
}

body{
  background-color: $gray__background;
}

CSS "output"

:root {
 --gray__background: #2d2d2d;
}

body{
 background-color: #2d2d2d;
}

That's what I was expecting to get:

CSS "output"

:root {
  --gray__background: #2d2d2d;
}
body{
  background-color: var(--gray__background);
}

Short story: I want to know if the result in the CSS "auto generated" file background-color: var(--gray__background);, instead of background-color: #2d2d2d; is possible to achieve.

I use the Live Sass Compiler extension for VSCode.

Sorry if my question is a little bit vague. I'm new to coding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-02-08 01:26:23

:root变量在SCSS中声明,但没有使用,因此它们不会显示在CSS输出上。
看来您必须在SCSS而不是$ GRAY__BACKGOUND中使用- gray__background,因此它变为:background-color:var(-gray__background) ;

希望这会有所帮助。

The :root variables are being declared in the SCSS, but are not being used, so they wouldn't show up on the CSS output.
It looks like you'll have to use --gray__background in the SCSS rather than $gray__background so it becomes: background-color: var(--gray__background);
.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文