Does SASS support inline IF statements?

11,415

Sass does support of conditional (ternary) operator or one line if statement as it works in languages like Javascript or PHP.

$variable: if(condition, result-when-true, result-when-false);

Article about improved if and what's new in Sass 3.3.
P.S. Before Sass 3.3 it did not work as it should. Issue in Sass repo.

Share:
11,415

Related videos on Youtube

Nick Carson
Author by

Nick Carson

Builder of ideas...

Updated on June 05, 2022

Comments

  • Nick Carson
    Nick Carson about 2 years

    I'd like to set a SASS variable using inline IF's similar to how its done in PHP or Javascript

    Is something like this possible?

    $myVar: ($something >= 10 ? true : false);
    

    I'm aware of @if control directives but I want to use a shorter inline syntax.

  • cimmanon
    cimmanon almost 10 years
    The if() function has been around a lot longer than 3.3. The only difference is that now it is lazily evaluated.