简体   繁体   English

使用可选参数减少混入

[英]Less mixin with optional parameters

I have a Less mixin defined as:我有一个Less mixin 定义为:

.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);

IE use the defaults for @weight , @style , @color IE 使用@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);

Produces this (note how color , font-weight , and font-style used the defaults):产生这个(注意colorfont-weightfont-style使用默认值):

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

See the documentation查看文档

http://lesscss.org/features/#mixins-parametric-feature-mixins-with-multiple-parameters http://lesscss.org/features/#mixins-parametric-feature-mixins-with-multiple-parameters

Note: you should get in the habit of using semicolons to separate parameters since some css values can contain commas.注意:您应该养成使用分号分隔参数的习惯,因为某些 css 值可以包含逗号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM