2

I am using a mixin for font like this:

#font {
  .trebuchet(@weight: normal, @size: 12px, @lineHeight: 20px, @style:normal) {
    font-family: "Trebuchet MS", arial, verdana, sans-serif;
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
    font-style: @style;
  }  
}

I want to call this changing only the last parameter, style, but leave the other values to their defaults. For example, instead of writing:

#font > .trebuchet(normal, 12px, 20px, italic);

I would write something like:

#font > .trebuchet(false, false, false, italic);

(which actually works, but I suspect for the wrong reasons -or anyway it doesn't seem proper syntax) What's the best way to achieve this?

Harry
  • 87,580
  • 25
  • 202
  • 214
periklis
  • 10,102
  • 6
  • 60
  • 68
  • 1
    See [Named Parameters](http://lesscss.org/features/#mixins-parametric-feature-named-parameters), e.g. `.trebuchet(@style: italic);`. – seven-phases-max Apr 14 '15 at 07:39

1 Answers1

3

You can use pattern matching. You should clone your .trebuchet class like this:

.trebuchet when (@weight=false) and (not(ispixel(@size)) and (not(ispixel(@lineHeight)) {
    font-style: @style;
}
sbagdat
  • 830
  • 11
  • 25