我有一个 Less
混合定义为:
.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;
}
如何定义用法,例如:
.fontStyle('NimbusSansNovCon-Reg', 12px, , , , 0.1em);
即@weight
、@style
、@color
最佳答案
要提供参数字符串最下方的参数,您还必须提供它要定义的预期变量。所以这个:
.fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em);
生成这个(注意 color
、font-weight
和 font-style
如何使用默认值):
font-family: 'NimbusSansNovCon-Reg';
font-size: 12px;
color: #ffffff;
font-weight: normal;
font-style: normal;
letter-spacing: 0.1em;
关于css - 减少带有可选参数的混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374887/