【问题标题】:Less mixin with optional parameters更少的带有可选参数的混合
【发布时间】:2013-06-11 13:13:46
【问题描述】:

我有一个Less mixin 定义为:

.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 的默认值

【问题讨论】:

    标签: css parameters less mixins


    【解决方案1】:

    要提供一个在参数字符串后面的参数,您还必须提供它要定义的预期变量。所以这个:

    .fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em);
    

    产生这个(注意colorfont-weightfont-style如何使用默认值):

    font-family: 'NimbusSansNovCon-Reg';
    font-size: 12px;
    color: #ffffff;
    font-weight: normal;
    font-style: normal;
    letter-spacing: 0.1em;
    

    【讨论】:

      【解决方案2】:

      查看文档

      http://lesscss.org/features/#mixins-parametric-feature-mixins-with-multiple-parameters

      注意:您应该养成使用分号分隔参数的习惯,因为某些 css 值可以包含逗号。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-05
        • 2013-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-23
        • 2021-02-28
        • 1970-01-01
        相关资源
        最近更新 更多