Less mixin and variables

前端 未结 1 1380
天命终不由人
天命终不由人 2021-01-22 14:03

I have the following mixin:

.iconFont(@color: @green, @font-size: 18px){
  color: @color;
  font-size: @font-size;
}

If I want only to change t

相关标签:
1条回答
  • 2021-01-22 15:00

    No, there is no need to specify the default value for the first parameter while calling the function. Instead you can just use named parameters feature to explicitly let the compiler know that the value you are passing in the mixin call is for the 2nd parameter.

    .sample{
        .iconFont(@font-size:14px);
    }
    

    The above Less code when compiled would produce the below output. (Note: I had set the @green as #00ff00.)

    .sample {
        color: #00ff00;
        font-size: 14px;
    }
    

    While using the named parameter feature, even the order in which the parameters are passed does not matter. For example, the same mixin can be called as follows:

    .sample2{
        .iconFont(@font-size:24px, @color: #070707);
    }
    

    And it would produce the below as output.

    .sample2 {
        color: #070707;
        font-size: 24px;
    }
    
    0 讨论(0)
提交回复
热议问题