list - Sass 返回“错误:("primary": #0075dd !important, ...) 不是有效的 CSS 值。” 动态创建新地图时
问题描述
每当我运行时,sass --watch src/sass:dist/css
我都会从命令行收到此错误
错误: ("primary": #0075dd !important, "secondary": #6b7a93 !important, "sucess": #1eaf3e !important) 不是有效的 CSS 值。
$map-theme-colors-rgb: create-map($map-theme-colors, convert-to-rgb, "value") !default; ^^^^^^^^^^^^^
这是一些代码片段。
_functions.scss
@function create-map($map, $callback-func, $args...) {
$_created-map: ();
@each $key, $value in $map {
$_args: ();
@each $arg in $args {
$_args: append(
$_args, if($arg == "key", $key, if($arg == "value", $value, $arg))
);
}
$_created-map: map.map-merge(
$_created-map,
meta.call(meta.get-function($callback-func), $_args...)
);
}
@return $_created-map;
}
_variables.scss
$map-theme-colors: (
"primary": $primary,
"secondary": $secondary,
"sucess": $sucess
) !default;
$map-theme-colors-rgb: create-map($map-theme-colors, convert-to-rgb, "value") !default;
我希望你能帮我解决这个问题。谢谢你。
解决方案
发现了问题。我希望这将帮助那些也在为同样的问题而苦苦挣扎的人。
使用颜色模块时:
@use "sass:color";
$color: "#ffbbcc"
$important-color: "#ffbbcc" !important;
// Sample function
@function toRGB($value) {
@return color.red($value), color.green($value), color.blue($value)
}
// $color is passed as "#ffbbcc" without the quotes
// and no problem.
$color-in-rgb: toRGB($color);
// but $important-color is passed as "#ffbbcc !important" without
// the quotes and throws an error because while #ffbbcc is a valid
// CSS color in hexadecimal, !important is not!
$important-color-in-rgb: toRGB($important-color);
所以解决方案是!important
在我的变量声明中删除:
$blue: "#0000ff"
像这样,而是把它放在我的地图上:
$some-color-map: (
"blue": $blue !important
);
推荐阅读
- asp.net-core - 如何使用 Blazor 语法折叠/展开 Razor 组件?
- python - 无法将我的 Python 脚本与 Linux 所需的所有模块和依赖项完全打包
- c# - 进程找不到指定的文件
- angular - Import typescript file to an angular typescript file
- python - FileNotFoundError: [WinError 3] 训练图像时系统找不到指定的路径
- java - 使用标准 API 删除?
- outlook-addin - Office.context.mailbox.getCallbackTokenAsync() 空令牌
- java - 我在世袭班的方法上有问题
- javascript - Javascript 文件加载回退。替代 document.write()
- ios - iOS 中 React Native 组件的映射