0

Is it possible to add sass if statements inside a css rule? To avoid repetition. I tried this, but sass complains about syntax.

@mixin outline($color, $shadow:'none') {

    text-shadow: 
        1px 0 0 $color,
        0 1px 0 $color, 
        0 -1px 0 $color, 
        -1px 0 0 $color

        @if $shadow != 'none' {
            , $shadow
        }
        ;
}

1 Answer 1

1

You can declare an array to store all shadows and then append $shadow if conditional statement is true

@mixin outline($color, $shadow: false) {
  $shadows: (
    1px 0 0 $color,
    0 1px 0 $color, 
    0 -1px 0 $color, 
    -1px 0 0 $color);

  @if $shadow {
    $shadows: append($shadows, $shadow);
  }
  text-shadow: $shadows;
}

Check out the SASS append function reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.