目录

Guard比较运算符(Guard Comparison Operators)

描述 (Description)

LESS包含五个保护比较运算符:,<=,> =和=。 您可以使用比较运算符(=)来比较数字,字符串,标识符等,其余运算符只能用于数字。

例子 (Example)

以下示例演示了在LESS文件中使用保护比较运算符 -

<!doctype html>
   <head>
      <title>Guard Comparison Operators</title>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
   </head>
   <body>
      <h2>Example of Guard Comparison Operators</h2>
      <p class = "myclass">Hello World!!!Welcome to IoWiki...</p>
   </body>
</html>

接下来,创建style.less文件。

style.less

.mixin (@a) when (@a = 20px){
color:red;
}
.mixin (@a) when (@a < 20px) {
   color:blue;
}
.mixin (@a) {
   font-size: @a;
}
.myclass { .mixin(20px) }

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

lessc style.less style.css

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

style.css

.myclass {
   color: red;
   font-size: 20px;
}

输出 (Output)

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

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

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

Mixin Guards
↑回到顶部↑
WIKI教程 @2018