Less-combinatorial-explosion

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

LESS-組み合わせ爆発

説明

  • &*は、コンマで区切られたリスト内のセレクターの可能なすべての順列を生成できます。

次の例は、*&*を使用して、LESSファイル内のセレクターのすべての可能な順列を生成する方法を示しています-

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css"/>
      <title>Combinatorial Explosion</title>
   </head>

   <body>
      <p>This is first paragraph.</p>
      <p>This is second paragraph which is adjecent to first paragraph ( i.e. p + p ). This will be highlighted.</p>
      <div>
         This div is adjecent to second paragraph ( i.e. p + div ). This will be highlighted.
      </div>

      <p>This is third paragraph adjecent to div ( i.e. p + div ). This will be highlighted.</p>
      <i>This is italic. This will not be highlighted since there is no (p + i) in CSS</i>
      <div>This is second div</div>
      <div>This is div adjecent to second div ( i.e. div + div ). This will be highlighted</div>
   </body>
</html>

次に、_style.less_ファイルを作成します。

style.less

p, div {
   color : red;
   font-family:Lucida Console;
   & + & {
      color : green;
      background-color: yellow;
      font-family: "Comic Sans MS";
   }
}

次のコマンドを使用して、_style.less_を_style.css_にコンパイルできます-

lessc style.less style.css

上記のコマンドを実行します。それは次のコードで自動的に_style.css_ファイルを作成します-

style.css

p,
div {
   color: red;
   font-family: Lucida Console;
}

p + p,
p + div,
div + p,
div + div {
   color: green;
   background-color: yellow;
   font-family: "Comic Sans MS";
}

出力

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

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

LESS Combinatorial Explosion