【发布时间】:2022-02-05 01:49:14
【问题描述】:
当我想生成颜色时遇到一些问题,它会显示错误消息 包含
“错误:$color: currentColor 不是颜色。”??
我不知道这个颜色是从哪里来的,也许是把 hex 转换成 rgb 的函数??
我的完整代码:
// Function to Convert Hex Color to RGB Color
@function hexToRGB($hex) {
@return red($hex), green($hex), blue($hex);
}
// Color Variables
$transparent: transparent !default;
$current: currentColor !default;
$white: #fff !default;
// Color Map
$shades: () !default;
$shades: map-merge(
(
"transparent": $transparent,
// The problem is Here it said :
// currentColor is not a color.
// Why??
"current": $current,
"white": $white,
),
$shades
);
// Global Color Map
$colors: () !default;
$colors: map-merge(
(
"shades": $shades,
),
$colors
);
@each $name, $value in $colors {
@each $shade, $color in $value {
.color-#{$shade} {
--color-example1: rgba(#{hexToRGB($color)}, 0);
}
}
}
编译成 CSS 后我想要得到的结果:
.color-transparent {
--color-example1: rgba(0, 0, 0, 0);
}
.color-current {
--color-example1: rgba(255, 255, 255, 0);
}
.color-white {
--color-example1: rgba(255, 255, 255, 0);
}
【问题讨论】:
-
currentColor应该是一个变量吗?它似乎从未被声明或定义...... -
我想将它生成为像tailwindCSS这样的颜色类
-
--tw-gradient-stops: var(--tw-gradient-from), currentColor, var(--tw-gradient-to, rgba(255, 255, 255, 0)) -
正如@AlexanderNied 指出的那样,
currentColor没有分配给它的值,因此您试图将非颜色传递给 rgba。 -
@AlexanderNied currentColor