Less mixin参数的默认值
我使用的是混合字体,如下所示:Less mixin参数的默认值,less,less-mixins,Less,Less Mixins,我使用的是混合字体,如下所示: #font { .trebuchet(@weight: normal, @size: 12px, @lineHeight: 20px, @style:normal) { font-family: "Trebuchet MS", arial, verdana, sans-serif; font-size: @size; font-weight: @weight; line-height: @lineHeight; font
#font {
.trebuchet(@weight: normal, @size: 12px, @lineHeight: 20px, @style:normal) {
font-family: "Trebuchet MS", arial, verdana, sans-serif;
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
font-style: @style;
}
}
.trebuchet when (@weight=false) and (not(ispixel(@size)) and (not(ispixel(@lineHeight)) {
font-style: @style;
}
我只想更改最后一个参数style,而将其他值保留为默认值。例如,不要写:
#font > .trebuchet(normal, 12px, 20px, italic);
我会这样写:
#font > .trebuchet(false, false, false, italic);
(这实际上是可行的,但我怀疑是因为错误的原因——或者说它的语法似乎不正确)
实现这一点的最佳方法是什么?您可以使用模式匹配。您应该像这样克隆.trebuchet类:
#font {
.trebuchet(@weight: normal, @size: 12px, @lineHeight: 20px, @style:normal) {
font-family: "Trebuchet MS", arial, verdana, sans-serif;
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
font-style: @style;
}
}
.trebuchet when (@weight=false) and (not(ispixel(@size)) and (not(ispixel(@lineHeight)) {
font-style: @style;
}
参见,例如.trebuchet(@style:italic)代码>。