目录

少 - CSS卫兵( CSS Guards)

描述 (Description)

防护用于匹配简单值或表达式上的许多参数。 它适用于CSS选择器。 它是声明mixin并立即调用它的语法。 要成功显示if类型语句; 加入这个功能& ,它允许您分组多个警卫。

例子 (Example)

以下示例演示了在LESS文件中使用css guard -

css_guard.htm

<!doctype html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
   </head>
   <body>
      <div class = "cont">
         <h2>Welcome to IoWiki</h2>
      </div>
      <div class = "style">
         <h3>The largest Tutorials Library on the web.</h3>
      </div>
   </body>
</html>

接下来,创建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 -

lessc style.less style.css

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

style.css

.style {
   background-color: blue;
   color: white;
}

输出 (Output)

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

  • 将上述html代码保存在css_guard.htm文件中。

  • 在浏览器中打开此HTML文件,将显示以下输出。

减少警卫
↑回到顶部↑
WIKI教程 @2018