英文:
SCSS - Lighten/Darken do not compile?
问题
在我的主文件styles.scss
中,我声明了一个变量:
$primary : #1e4f9c;
$change : 15%;
然后我导入另一个SCSS文件:
@import "/project-assets/css/layout.scss";
在那个文件中,我创建了CSS变量:
:root {
--primary: #{$primary};
--primary-light: lighten(#{$primary}, #{$change});
--primary-dark: darken(#{$primary}, #{$change});
}
但出于某种原因,这里的输出不是新的十六进制值,而是函数调用保持不变:
:root {
--primary: #1e4f9c;
--primary-light: lighten(#1e4f9c, 15%);
--primary-dark: darken(#1e4f9c, 15%);
}
我发现lighten
函数在使用百分比时不像预期那样工作,将它更改为color.scale
,但输出仍然是SCSS,没有变成十六进制。我在这里漏掉了什么?
英文:
In my main file styles.scss
I have declared a variable:
$primary : #1e4f9c;
$change : 15%;
Then I import another SCSS file:
@import "/project-assets/css/layout.scss";
In that file I create CSS variables:
:root {
--primary: #{$primary};
--primary-light: lighten(#{$primary}, #{$change});
--primary-dark: darken(#{$primary}, #{$change});
}
but for some reason the output here is not the new HEX values but the function call stays as it is:
:root {
--primary: #1e4f9c;
--primary-light: lighten(#1e4f9c, 15%);
--primary-dark: darken(#1e4f9c, 15%);
}
I found out that lighten function doesn't work as expected with percentage and changed it to color.scale
but the output is still in SCSS not changed into a HEX. What am I missing here?
答案1
得分: 2
CSS变量只能存储静态值,不能存储函数?请尝试以下方式:
$primary: #1e4f9c;
$change: 15%;
:root {
--primary: #{$primary};
--primary-light: #{lighten($primary, $change)};
--primary-dark: #{darken($primary, $change)};
}
英文:
Css variables can store only static values, not functions ? Try this instead:
$primary: #1e4f9c;
$change: 15%;
:root {
--primary: #{$primary};
--primary-light: #{lighten($primary, $change)};
--primary-dark: #{darken($primary, $change)};
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论