Stephen Thomas Stephen Thomas - 3 months ago 11
Sass (Sass) Question

SCSS if function without false (else) clause

Anyone know of a way to use the SASS

if
function (not the
@if
directive) without a false (aka else) clause?

Use Case: I have a SASS library that's normally used on its own and includes a full CSS reset. Someone wants to take an individual file from the library and add it to a project that includes Zurb Foundation, which, of course, totally destroys the CSS reset. I'd like to accommodate that use case with something like:

$css-reset: false !default;

.form__input {
border-radius: 4px if(not $css-reset, !important);
}


That's a SASS compile error, though, since the compiler requires a third parameter to the
if()
function.

Thanks in advance

Answer

Not super elegant, but this works:

border-radius: 4px if(not $css-reset, !important, unquote("");
Comments