gpt4 book ai didi

css - 在 scss 中从绿色到红色

转载 作者:行者123 更新时间:2023-11-28 11:03:55 25 4
gpt4 key购买 nike

我正在为这个元素使用 SCSS。

我需要根据百分比值创建从绿色到红色的 100 个类。所以 100% 是绿色,0% 是红色。

我想让它淡出,所以在大约 50% 时它会变成橙色等。

我想您可以使用 SASS 做一些事情,但我什至不知道从哪里开始。

提前致谢

最佳答案

Sass 有一个原生的原生混合函数 mix($color-1, $color-2, $weight)$weight 是您添加的 $color-1 的百分比。

引用:http://sass-lang.com/documentation/Sass/Script/Functions.html

下面的循环将生成 101 个类 .class-0 ... .class-100,从 0% 红色切换到 100% 红色。

@for $i from 0 through 100 {
.color-#{$i}{ background: mix(red, green, $i);}
}

结果:

enter image description here

关于css - 在 scss 中从绿色到红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41928211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com