可选参数的Less mixin

32

我有一个名为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方面使用默认设置。

2个回答

37

要向参数列表中的较深层级提供参数,您还必须提供它所定义的预期变量。因此,以下代码:

.fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em);

生成以下结果(请注意colorfont-weightfont-style使用了默认值):

font-family: 'NimbusSansNovCon-Reg';
font-size: 12px;
color: #ffffff;
font-weight: normal;
font-style: normal;
letter-spacing: 0.1em;

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接