LESS- CSS LESS

描述

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

示例

以下示例演示了在LESS文件中使用 css Guards :

css_guard.htm

<!doctype html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
   </head>

   <body>
      <div class = "cont">
         <h2>Welcome to TutorialsPoint</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;
}

输出

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

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

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

Less css guard