Skip to content

Instantly share code, notes, and snippets.

@pdechery
Last active May 31, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdechery/3facf96afea275a40b6caaaf4a025796 to your computer and use it in GitHub Desktop.
Save pdechery/3facf96afea275a40b6caaaf4a025796 to your computer and use it in GitHub Desktop.
LESS loop sobre array de cores
/*
Aplicar cores dinamicamente numa lista
a partir de um loop sobre um "array" de
elementos usando LESS
Referência -> http://lesscss.org/functions/#list-functions
*/
@azulescuro: #003367;
@ciano: #3078C0;
@vermelho: #EF5F4B;
@amarelo: #FFC742;
@verdeagua: #15949D;
// "lista" das cores (LESS n tem array, mas tem "listas")
@cores: @azulescuro, @ciano, @vermelho, @amarelo, @verdeagua;
// limites para o loop
@from : 1;
@to : length(@cores);
// seletor
ul {
li {
list-style-type: none;
padding: 0;
margin: 0;
// loop
.loop(@index) when(@index =< @to) {
&:nth-child(@{index}):before {
content: "";
display: inline-block;
width: 1em;
height: 1em;
background-color: extract(@cores, @index);
}
.loop(@index + 1);
}
.loop(@from);
}
}
@cezaraugusto
Copy link

voodoo brabo 👻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment