是否可以在 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/