CrazySynthax
CrazySynthax

Reputation: 14988

SCSS: How to use variables to write style classes ?

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;
   }
}

Upvotes: 0

Views: 106

Answers (1)

karthick
karthick

Reputation: 12176

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;
   }
}

Upvotes: 2

Related Questions