减少与可选参数的混合 [英] Less mixin with optional parameters
本文介绍了减少与可选参数的混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Less
mixin 定义为:
I have a Less
mixin defined as:
.fontStyle(@family, @size, @weight: normal, @style: normal, @color: #ffffff, @letter-spacing: normal) {
font-family: @family;
font-size: @size;
color: @color;
font-weight: @weight;
font-style: @style;
letter-spacing: @letter-spacing;
}
我如何定义用法,例如:
How can I define usage like:
.fontStyle('NimbusSansNovCon-Reg', 12px, , , , 0.1em);
I.E.使用 @weight
、@style
、@color
推荐答案
要提供一个在参数字符串后面的参数,您还必须提供它要定义的预期变量.所以这个:
To supply a parameter that far down the string of arguments, you have to also supply the expected variable it is to define. So this:
.fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em);
产生这个(注意 color
、font-weight
和 font-style
如何使用默认值):
Produces this (note how color
, font-weight
, and font-style
used the defaults):
font-family: 'NimbusSansNovCon-Reg';
font-size: 12px;
color: #ffffff;
font-weight: normal;
font-style: normal;
letter-spacing: 0.1em;
这篇关于减少与可选参数的混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文