32

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. use the defaults for @weight, @style, @color

ScottS
  • 71,703
  • 13
  • 126
  • 146
Justin
  • 42,716
  • 77
  • 201
  • 296

2 Answers2

37

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):

font-family: 'NimbusSansNovCon-Reg';
font-size: 12px;
color: #ffffff;
font-weight: normal;
font-style: normal;
letter-spacing: 0.1em;
ScottS
  • 71,703
  • 13
  • 126
  • 146
2

See the documentation

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.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689