I was wondering if you can get an element index for the @each loop.
I have the following code, but I was wondering if the $i
variable was the best way to do this.
Current code:
$i: 0;
$refcolors: #55A46A, #9BD385, #D9EA79, #E4EE77, #F2E975, #F2D368, #F0AB55, #ED7943, #EA4E38, #E80D19;
@each $c in $refcolors {
$i: $i + 1;
#cr-#{$i} strong {
background:$c;
}
}
To update this answer: yes you can achieve this with the
@each
loop:Source: http://12devs.co.uk/articles/handy-advanced-sass/
Sometimes you may need to use an array or a map. I had an array of arrays, i.e.:
I found that it was easiest to just convert it to an object:
And use the following to get
$i
:The sass team also recommended the following, although I'm not much of a fan:
link.
First of all, the
@each
function is not from Compass, but from Sass.To answer your question, this cannot be done with an each loop, but it is easy to convert this into a
@for
loop, which can do this: