教程 > less 教程 > 阅读:19

less css guards——迹忆客-ag捕鱼王app官网

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

按照以下步骤查看上述代码的工作原理

  • 将上述 html 代码保存在 css_guard.html 文件中。
  • 在浏览器中打开此 html 文件,将显示以下输出。

less css guard

查看笔记

扫码一下
查看教程更方便
网站地图