MENO - Selettori in Mixins

Descrizione

Le mixine possono contenere non solo proprietà ma possono contenere anche selettori.

Esempio

L'esempio seguente mostra l'uso dei selettori mixin nel file LESS -

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>Selectors in Mixins</title>
   </head>

   <body>
      <h2>Welcome to Tutorialspoint</h2>
      <a href="http://www.tutorialspoint.com/">Tutorialspoint</a>
   </body>
</html>

Quindi, crea il file style.less .

style.less

.mixin() {
   &:hover {
      background: #FFC0CB;
   }
}

a {
   .mixin();
}

Puoi compilare style.less in style.css usando il seguente comando:

lessc style.less style.css

Esegui il comando precedente; creerà automaticamente il file style.css con il seguente codice:

style.css

a:hover {
   background: #FFC0CB;
}

Produzione

Segui questi passaggi per vedere come funziona il codice sopra:

  • Salva il codice html sopra nel file less_mixin_selectors.html file.

  • Apri questo file HTML in un browser, verrà visualizzato il seguente output.