Less-guard-comparison-operators

提供:Dev Guides
移動先:案内検索

LESS-ガード比較演算子

説明

LESSには、<、>、⇐、> =、=の5つのガード比較演算子が含まれています。 比較演算子(=)を使用して数字、文字列、識別子などを比較できます。残りの演算子は数字でのみ使用できます。

次の例は、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 finddevguides...</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;
}

出力

上記のコードがどのように機能するかを確認するには、次の手順に従ってください-

  • 上記のHTMLコードを guard_comparison_operatorsl ファイルに保存します。
  • このHTMLファイルをブラウザで開くと、次の出力が表示されます。

Mixin Guards