0

I was wondering whether there is a certain way to use variables that affect the style in SCSS.

I'm looking for something like:

var x = 1
.class1 { 
   if (x==1) {
       background-color: red;
   } else { 
       background-color: blue;
   }
}
.class2 { 
   if (x==1) {
       background-color: blue;
   } else { 
       background-color: red;
   }
}
CrazySynthax
  • 13,662
  • 34
  • 99
  • 183

1 Answers1

2

You can use @if and @else

$x:1;

.class1 { 
   @if $x == 1 {
       background-color: red;
   } @else { 
       background-color: blue;
   }
}
.class2 { 
    @if $x == 1 {
       background-color: blue;
   } @else { 
       background-color: red;
   }
}
karthick
  • 11,998
  • 6
  • 56
  • 88