SASS变量未正确解析 - 未定义变量:“$ ct-white” [英] SASS variables not parsing correctly - Undefined variable: "$ct-white"

查看:2840
本文介绍了SASS变量未正确解析 - 未定义变量:“$ ct-white”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用SASS,我的变量似乎已停止工作。我在我的 application.css.scss 文件中有以下代码:

I am using SASS for the first time, and my variables seem to have stopped working. I have the following code in my application.css.scss file:

*= require_self
*/
@import "layout";
@import "colors";
...
@import "text";

在我的部分 _colors.css.scss 文件,有:

...
$ct-white: #F8F8F8 !global;

和在我的部分 _layout.css.scss file(Rails默认布局文件):

and in my partial _layout.css.scss file (the Rails default layout file):

/* Site-wide layout syntax */
body {
  background-color: $ct-white;
}



我知道 _layout.css.scss 文件加载,因为页面上的其他样式工作正常,当我设置 body {background-color:#F8F8F8; } 。由于某些原因,该变量未正确解析。

I know that the _layout.css.scss file is loading because other styles on the page work fine when I set body { background-color: #F8F8F8; }. For some reason, the variable isn't being parsed correctly.

任何想法为什么?

推荐答案

布局之后导入颜色,因此您在 colors 不适用于 layout 。你可以简单地反转这两行的顺序。在SASS中,进口订单很重要。

You're importing colors after layout , so the variables you define in colors are not available for layout. You could simply invert the order of those two lines. In SASS, import order matters.

这篇关于SASS变量未正确解析 - 未定义变量:“$ ct-white”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆