Using multiple conditions (AND) in SASS IF statement

后端 未结 2 1214
闹比i
闹比i 2020-12-12 19:17

Using SASS, I would like to have multiple condition in IF statement

What I use right now :

@function color-x ($alpha) {
    @if             


        
相关标签:
2条回答
  • 2020-12-12 19:32

    You can also do:

    @if index("foo" "bar", $value) { .. }
    

    Beware though:

    1. It might not be quite obvious what you are trying to do.
    2. It returns a number or null, not a boolean.
    0 讨论(0)
  • 2020-12-12 19:37

    From the Sass language reference documentation:

    Boolean Operations

    SassScript supports and, or, and not operators for boolean values.

    (link)

    So an if statement expression with a compound condition would look like this:

    @if $var1 == value1 and $var2 == value2 {
        // ...
    }
    

    Further, parentheses can be used to affect the order of operations in a more complicated expression:

    @if ($var1 == value1 and not ($var2 == value2)) or ($var3 == value3) {
        // ...
    } 
    
    0 讨论(0)
提交回复
热议问题