CSS SASS if else if语句

时间:2015-02-26 18:25:47

标签: css sass

如果在SASS中可以使用else吗?

像这样:

if(1+1 = 1) {

} else if(2+1=4) {

} else {

}

我有以下内容并且不起作用:

$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

1 个答案:

答案 0 :(得分:4)

根据SASS参考: Yes, is it possible

甚至多次:

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