少混合与可选参数 [英] Less mixin with optional parameters

查看:131
本文介绍了少混合与可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更少 mixin定义为:

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;
}

我如何定义用法:

.fontStyle('NimbusSansNovCon-Reg', 12px, , , , 0.1em);

I.E。使用默认值 @weight @style @color

I.E. use the defaults for @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);

产生这个(注意 color code> font-weight 和 font-style 使用默认值):

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;

这篇关于少混合与可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆