Created
December 12, 2012 08:54
-
-
Save MoOx/4266210 to your computer and use it in GitHub Desktop.
Is there a sort of ternary operator in #Sass ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
$background: null; // if you don't do this, background is undefined out of the @if/else scope | |
@if ($direction) { | |
$background: linear-gradient($direction, $color, $color2); | |
} | |
@else { | |
$background: linear-gradient($color, $color2); | |
} | |
//... | |
// can we do something like this ? | |
$background: $direction ? /* value */ : /* other value */; |
Added to SASS 3.1.2 chriseppstein/sass@b9a9e14
you could mimic the behaviour with your own functions like,
@function if($condition, $if-value, $else-value) {
@if ($condition == true) {
@return $if-value;
} @else {
@return $else-value;
}
}
In sass 3.3, the if
function only evaluates the argument that corresponds to the condition. This makes the if function as powerful as the @if
directive.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, looks like