似乎已评估的颜色字符串无法与某些内置的LESS功能配合使用。我尝试使用e()
和~""
以及两者的任意组合。
我可能会针对我的特殊情况找到解决方法,我只是问这是否是这种预期的行为,或者我的推理是否有错?任何见解表示赞赏。
例如,在这里,颜色是根据求值字符串创建的;注意#
十六进制值中的“丢失” ,稍后会添加:
.broken-mixin(@hexcode: '9719e1') {
@color: e("#@{hexcode}");
// this works as expected
background-color: @color;
// this does work too
.very-simple-mixin(@color);
// Undefined_methodError: error evaluating function `fade`:
// Object #<Object> has no method 'toHSL'
background-color: fade(@color,30%);
// SyntaxError: error evaluating function `red`:
// Cannot read property '0' of undefined
background-color: rgba(red(@color), green(@color), blue(@color), 0.5);
}
否则,内置函数通常可以与mixins中的变量一起使用,例如:
.mixin-works(@myColor: #00ff00) {
// works just fine
background-color: fade(@myColor,30%);
// or this, works too
background-color: rgba(red(@myColor), green(@myColor), blue(@myColor), 0.5);
}
我想念什么?
引用LESS网站的功能参考:
褪色
设置颜色的绝对透明度。可以将其应用于颜色,无论它们是否已经具有不透明度值。
参数:
color:颜色对象。
数量:0-100%的百分比。
该fade
函数需要一个color
对象作为输入,因此将评估字符串作为参数传递给该函数不起作用。
可以使用内置color
函数将字符串转换为等效color
对象,如下所示:
background-color: fade(color("@{color}"),30%);
其他内置函数也由于相同的原因而无法正常工作(也就是说,它们希望将color
对象作为输入)。
红色的:
提取颜色对象的红色通道。
参数: color-颜色对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句