Last active
May 31, 2016 14:48
-
-
Save pdechery/3facf96afea275a40b6caaaf4a025796 to your computer and use it in GitHub Desktop.
LESS loop sobre array de cores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
voodoo brabo 👻