@each loop with index

后端 未结 3 818
渐次进展
渐次进展 2020-12-23 14:23

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 t

3条回答
  •  庸人自扰
    2020-12-23 14:55

    To update this answer: yes you can achieve this with the @each loop:

    $colors-list: #111 #222 #333 #444 #555;
    
    @each $current-color in $colors-list {
        $i: index($colors-list, $current-color);
        .stuff-#{$i} { 
            color: $current-color;
        }
    }
    

    Source: http://12devs.co.uk/articles/handy-advanced-sass/

提交回复
热议问题