MOINS - Explosion combinatoire

La description

le & peut produire toutes les permutations possibles de sélecteurs dans une liste séparée par des virgules.

Exemple

L'exemple suivant montre l'utilisation de & pour produire toutes les permutations possibles des sélecteurs dans le fichier 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>

Ensuite, créez le fichier style.less .

sans style

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

Vous pouvez compiler le style.less en style.css en utilisant la commande suivante -

lessc style.less style.css

Exécutez la commande ci-dessus; il créera automatiquement le fichier style.css avec le code suivant -

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";
}

Production

Suivez ces étapes pour voir comment fonctionne le code ci-dessus -

  • Enregistrez le code html ci-dessus dans le combinatorial_explosion.html fichier.

  • Ouvrez ce fichier HTML dans un navigateur, la sortie suivante s'affichera.