css - 减少带有可选参数的混合

标签 css parameters less mixins

我有一个 Less 混合定义为:

.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);

@weight@style@color

使用默认值

最佳答案

要提供参数字符串最下方的参数,您还必须提供它要定义的预期变量。所以这个:

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

关于css - 减少带有可选参数的混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374887/

相关文章:

javascript - 幻灯片上的图像向下跳跃

鼠标向上/向下滚动类的 Javascript 奇怪行为

jquery - 这个 jquery 语法是什么?

html - 带有类的图形标签中的 img 标签不起作用

css - 如何将此 css 代码翻译成更好的 lesscss 代码?

css - 是否可以显式设置匿名 flex 元素的样式?

html - 将图像居中并使其适合网站的屏幕(非常简单)

function - 如何将函数及其参数传递给另一个函数

c++ - 为什么我们需要默认构造函数来在 C++ 中通过引用传递对象?

css - LESS.js 编译了 css 但没有应用它?