扫码一下
查看教程更方便
guard 用于匹配简单值或表达式上的多个参数。 它应用于 css 选择器。 它是声明 mixin 并立即调用它的语法。 成功带出if类型语句; 使用功能 &
加入此功能,它允许我们对多个 guard 进行分组。
以下示例演示了在 less 文件中使用 css guard
css_guard.html
welcome to 迹忆客
the largest tutorials library on the web.
现在,创建 style.less 文件。
style.less
@usedscope: global; .mixin() { @usedscope: mixin; .cont when (@usedscope = global) { background-color: red; color: black; } .style when (@usedscope = mixin) { background-color: blue; color: white; } @usedscope: mixin; } .mixin();
我们可以使用以下命令将 style.less 编译为 style.css
style.css
.style { background-color: blue; color: white; }
按照以下步骤查看上述代码的工作原理