Is it possible to pass !important as parameter/option for LESSCSS mixins?

孤街醉人 提交于 2019-11-30 07:37:39

问题


This is what I already have:

.coloring(@color){
    color:@color;
}

But this is what I actually wanted to do:

.coloring(@color, @important:''){
    color:@color @important;
    //etc 
}

So I could call:

.coloring(@color, !important);

But I get the error message "ParseError: Unrecognised input"


Is there a way to tell this mixin optoinally to use "!important" for the CSS statements?


回答1:


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');).

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 ).

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 original 1-parameter mixin (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).



来源:https://stackoverflow.com/questions/22936703/is-it-possible-to-pass-important-as-parameter-option-for-lesscss-mixins

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!