mixin 参数的默认值
我正在使用像这样的字体混合:
#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;
}
}
我想调用它仅更改最后一个参数样式,但将其他值保留为默认值。例如,我不会写:
#font > .trebuchet(normal, 12px, 20px, italic);
我会写类似的内容:
#font > .trebuchet(false, false, false, italic);
(这实际上有效,但我怀疑出于错误的原因 - 或者无论如何它看起来不正确的语法) 实现这一目标的最佳方法是什么?
I am using a mixin for font like this:
#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;
}
}
I want to call this changing only the last parameter, style, but leave the other values to their defaults. For example, instead of writing:
#font > .trebuchet(normal, 12px, 20px, italic);
I would write something like:
#font > .trebuchet(false, false, false, italic);
(which actually works, but I suspect for the wrong reasons -or anyway it doesn't seem proper syntax)
What's the best way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用模式匹配。你应该像这样克隆你的 .trebuchet 类:
You can use pattern matching. You should clone your .trebuchet class like this: