Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更少的css编译器。无法使用变暗属性_Css_Less - Fatal编程技术网

更少的css编译器。无法使用变暗属性

更少的css编译器。无法使用变暗属性,css,less,Css,Less,我正在开发一个使用LESS作为CSS编译器的项目。 我已经有了一个完整的循环,可以正确设置背景色 我的问题是: 在我当前的代码中,当我尝试使用darken属性时,编译结果如下: SyntaxError:错误求值函数变暗:Object#has 没有“toHSL”方法 代码是这样的: @colors: "008B8B", "00CDCD", "00EEEE"; /* Colors and background loop (based on colors.less arrays) */ .loop-

我正在开发一个使用LESS作为CSS编译器的项目。 我已经有了一个完整的循环,可以正确设置背景色

我的问题是: 在我当前的代码中,当我尝试使用darken属性时,编译结果如下:

SyntaxError:错误求值函数
变暗
:Object#has 没有“toHSL”方法

代码是这样的:

@colors:
"008B8B",
"00CDCD",
"00EEEE";

/* Colors and background loop (based on colors.less arrays) */
.loop-colors(@index) when (@index > 0){ // loop to generate rules for each color
  .loop-colors(@index - 1);// call for the next iteration
  @color: e(extract(@colors, @index));
  @hexColor:  ~'#@{color}';
  @border: 1px solid darken(@hexColor, 5%);
  &.col-@{color}{
    background: @hexColor;
    border:@border;
  }
}
我不知道这为什么不好

我的意思是,我认为这是因为颜色列表在每种颜色之前没有“#”,但仅仅因为我在css类上也使用了它,我不能将它添加到@colors,所以我必须稍后添加它

我不知道稍后添加“#”是否以及为什么会影响变暗属性,以及如何影响


谢谢

正如@seven phases max所提到的,
~'{color}'
将不会创建颜色,而是创建字符串。要将字符串转换为颜色,可以使用函数

@colors:
  "008B8B",
  "00CDCD",
  "00EEEE";

/* Colors and background loop (based on colors.less arrays) */
.loop-colors(@index) when (@index > 0) { // loop to generate rules for each color
  .loop-colors(@index - 1);// call for the next iteration
  @color: e(extract(@colors, @index));
  @hexColor:  ~'#@{color}';
  @border: 1px solid darken(color(@hexColor), 5%);
  &.col-@{color} {
    background: @hexColor;
    border: @border;
  }
}

~'#@{color}'
创建字符串值而不是颜色。要从字符串创建颜色对象(颜色函数所期望的),请使用
color
函数,例如
color(“#@{color}”)
。感谢的可能重复,但现在我在尝试编译时出现以下错误:致命错误:调用和重试分配失败-内存不足处理如何解决?Thanks@lam似乎你的Less生成器的一个bug是由你的Less代码触发的。必须有一个无限循环,它在构建一些特殊代码时不会中断。在谷歌搜索之后,我发现了一个可能有用的方法。顺便说一下,您可以在StackOverflow上添加关于此问题的另一个问题。