Sass: Change color with @for loop

前端 未结 3 696
独厮守ぢ
独厮守ぢ 2021-01-03 01:49

I try to darken a variable number of divs like that \"enter with following code:



        
3条回答
  •  迷失自我
    2021-01-03 02:37

    You can darken the color using $i inside @for and apply respective classes to the divs. Hope this helps.

    SCSS

    @mixin color-divs ($count, $baseName, $startcolor) {
        @for $i from 0 through $count {
            $background-color: darken($startcolor, $i * $i); 
        .colored-div#{$i} {
          background: $background-color;
          height:100px;
          width:200px;
          float: left;
          margin-right: 5px;
        }
       }
    
    }
     @include color-divs(5,'a',#ffd8b1);
    

    HTML

    a
    b
    c
    d
    e

    Demo

    See demo

提交回复
热议问题