Less mixin with optional parameters

前端 未结 2 2020
感动是毒
感动是毒 2020-12-10 00:45

I have a Less mixin defined as:

.fontStyle(@family, @size, @weight: normal, @style: normal, @color: #ffffff, @letter-spacing: normal) {
  font-f         


        
相关标签:
2条回答
  • 2020-12-10 01:25

    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.

    0 讨论(0)
  • 2020-12-10 01:39

    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;
    
    0 讨论(0)
提交回复
热议问题