Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS: loop inside properties

Tags:

css

sass

I want to generate multiple values for a single property:

background-image:
    radial-gradient(circle, $primary 10%, transparent 10%),
    radial-gradient(circle, $primary 10%, transparent 10%),
    radial-gradient(circle, $primary 10%, transparent 10%),
    radial-gradient(circle, $primary 10%, transparent 10%);

I tried to achieve this by doing this:

background-image:
    @for $i from 1 to 5 {
        radial-gradient(circle, $primary 10%, transparent 10%),
    }

However, this doesn't work. Any help would be appreciated!

like image 961
sdvnksv Avatar asked Oct 24 '25 09:10

sdvnksv


1 Answers

Just declare a variable before and use it after all your logic.

BTW, you can play also with the $i and colors like $color#{$i}.

.gradient{
  $color1: #000;
  $color2: #fff;
  $background: null;

  @for $i from 1 through 4 {
      $background: $background radial-gradient(circle, $color1 10%, $color2 10%)#{if($i !=4, ',', '')};
  }

  background-image: $background;
}
like image 74
llobet Avatar answered Oct 26 '25 23:10

llobet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!