cycling through a list of colors with sass

前端 未结 1 678

It is possible to have list of three colors:

$color-list: x y z;

And then apply these three colors by cycling through them and adding them to on an unordere

相关标签:
1条回答
  • 2020-11-27 20:46

    If its possible with pure CSS, its possible with Sass. This will work with any number of colors:

    http://codepen.io/cimmanon/pen/yoCDG

    $colors: red, orange, yellow, green, blue, purple;
    
    @for $i from 1 through length($colors) {
        li:nth-child(#{length($colors)}n+#{$i}) {
            background: nth($colors, $i)
        }
    }
    

    Output:

    li:nth-child(6n+1) {
      background: red;
    }
    
    li:nth-child(6n+2) {
      background: orange;
    }
    
    li:nth-child(6n+3) {
      background: yellow;
    }
    
    li:nth-child(6n+4) {
      background: green;
    }
    
    li:nth-child(6n+5) {
      background: blue;
    }
    
    li:nth-child(6n+6) {
      background: purple;
    }
    
    0 讨论(0)
提交回复
热议问题