CSS SASS if else if 语句

标签 css sass

是否可以在 SASS 中使用 else if ?

像这样:

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

最佳答案

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

关于CSS SASS if else if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28749974/

相关文章:

twitter-bootstrap - Bootstrap sass + gulp : Media query expression must begin with '('

css - SASS:@media 查询不工作

html - 为什么我的 css Class 应用不一致?

jquery - dropmenu 溢出而没有扩展横幅图像

html - 居中列表项

ruby-on-rails - 在scss中编译错误

html - LI 中带有图标图像的响应式文本宽度

img 上的 css 绝对定位,改变大小

css - IE8位置错误

css - gulp-sass 似乎没有解决进口问题