@else if語句用來與@if指令一起使用。當 @if 語句失敗時,則 @else if 語句測試,如果它們也無法測試滿足時再 @else 執行。
語法:
@if expression { // CSS codes } @else if condition { // CSS codes } @else { // CSS codes }
scss代碼實例:
$type: audi; p { @if $type == benz { color: red; } @else if $type == mahindra { color: blue; } @else if $type == audi { color: green; } @else { color: black; } }
編譯后的css代碼如下:
p { color: green; }