LESS - default 默认函数

描述

仅当默认函数在保护条件内可用且与任何其他 mixin 不匹配时,它才返回 true,否则返回 false。当默认函数在 mixin 保护条件之外使用时,它会解释为常规 css。

示例

以下示例演示了在 LESS 文件 − 中使用默认函数

以下是使用扩展名 .less 保存的样式表文件;这类似于 CSS 文件。

style.less

.mixin(1)                   {a: 5}
.mixin(2)                   {b: 10}
.mixin(3)                   {c: 15}
.mixin(@a) when (default()) {d: @a}

div {
   .mixin(12);
}

div.style {
   .mixin(3);
}

您可以使用以下命令将 style.less 文件编译为 style.css

lessc style.less style.css

执行上述命令;它将使用以下代码自动创建 style.css 文件 −

style.css

div {
   d: 12;
}
div.special {
   c: 15;
}

less_misc_functions.html