2

Is it possible to use an else if in SASS?

Like this:

if(1+1 = 1) {

} else if(2+1=4) {

} else {

}

I have the following and it doesn't work:

$color: "blue", "green", "orange", "red", "pink", "grey", "black"

@for $i from 1 through length($color)
  .color-#{ nth($color, $i) }
    @if nth($color, $i) == "pink" or "grey"
      color: #f00
    @else if nth($color, $i) == "black"
      color: #0f0
    @else if nth($color, $i) == "orange"
      color: #000
    @else
      color: #fff
gespinha
  • 7,968
  • 16
  • 57
  • 91

1 Answers1

4

According to the SASS reference: Yes, is it possible.

Even multiple times too:

SASS:

p 
  @if $type == ocean 
    color: blue
  @else if $type == matador
    color: red
  @else if $type == monster
    color: green
  @else
    color: black

SCSS:

p {
  @if $type == ocean {
    color: blue;
  } @else if $type == matador {
    color: red;
  } @else if $type == monster {
    color: green;
  } @else {
    color: black;
  }
DNReNTi
  • 521
  • 4
  • 18