@each loop with index

后端 未结 3 812
渐次进展
渐次进展 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 15:15

    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:

    @for $i from 1 through length($refcolors) {
        $c: nth($refcolors, $i);
    
        // ... do something fancy with $c
    }
    

提交回复
热议问题