Less-css-guards

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

LESS-CSSガード

説明

ガードは、式の単純な値またはいくつかの引数を照合するために使用されます。 CSSセレクターに適用されます。 これは、mixinを宣言してすぐに呼び出すための構文です。 if typeステートメントを正常に引き出すため。複数のガードをグループ化できる機能*&*でこれに参加します。

次の例は、LESSファイルでの css ガードの使用を示しています-

css_guard

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

   <body>
      <div class = "cont">
         <h2>Welcome to finddevguides</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 ファイルに保存します。
  • このHTMLファイルをブラウザで開くと、次の出力が表示されます。

Less css guard