SCSS – Lighten/Darken do not compile?

huangapple go评论63阅读模式
英文:

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%);
}

SCSS – Lighten/Darken do not compile?

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?

SCSS – Lighten/Darken do not compile?

答案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)};
}

huangapple
  • 本文由 发表于 2023年2月24日 16:56:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554463.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定