是否可以传递!important作为LESSCSS mixins的参数/选项? [英] Is it possible to pass !important as parameter/option for LESSCSS mixins?
问题描述
这是我已经有的:
.coloring(@color){
color:@color;
}
实际上想做:
But this is what I actually wanted to do:
.coloring(@color, @important:''){
color:@color @important;
//etc
}
所以我可以调用:
.coloring(@color, !important);
但我得到错误信息ParseError:Uncognible input
But I get the error message "ParseError: Unrecognised input"
有没有办法让这个混合在视觉上对CSS语句使用!important? $ b
推荐答案
请参阅重要关键字。例如。可以使用 .coloring(red)!important;
w / o mixin更改。
或者对于修改的mixin使用转义,因为!
是mixin参数值中不允许的符号(即 .coloring(red,〜'!重要');
)。
See The !important keyword. E.g. can just use .coloring(red) !important;
w/o mixin changes.
Or use escaping for the modified mixin since !
is not allowed symbol in mixin parameter values (i.e. .coloring(red, ~'!important');
).
还要注意''
因为 @important
参数不正确,因为省略此参数的mixin调用将导致无效 color:color'';
c> CSS(使用 @important ...
或 @important:〜''
默认值)。
Also note that the default value of ''
for the @important
parameter is not correct since the mixin call with this parameter omitted will result in invalid color: color '';
CSS (use @important...
or @important: ~''
if you need an "empty" default value ).
PS也不要错过,你可以提供颜色和!important
值作为一个参数,即 .coloring(red〜'!important'); 也将是正确的方法来调用您的初始方法(如果您只需要
color
属性以使!important
修饰符与
.coloring(红色)!重要;
语法相反!important
适用于所有CSS属性在mixin中)。
P.S. Also do not miss that you can supply both color and !important
values as a single parameter, i.e. .coloring(red ~'!important');
would be also correct method to invoke your initial method (if you need only color
property to have the !important
modifier contrary to .coloring(red) !important;
syntax where !important
applies to all CSS properties within the mixin).
这篇关于是否可以传递!important作为LESSCSS mixins的参数/选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!