Search code examples
sassrgba

SASS mixin using SASS rgba() function not working with interpolation


The SASS documentation says rgba function can be called in 2 ways.

I created a codepen to demonstrate the rgba function in a mixin I am having problems with:

$hd-color1: #366dbd;    // heading color
$hd-shadow1: 0.24;      // text shadow opacity

@mixin ColorAndTextShadow($color, $opacity) {
  color: $color;
  text-shadow: 3px 1px rgba( #{$color}, #{$opacity} );
}

h2 {
  @include ColorAndTextShadow ( #{$hd-color1}, #{$hd-shadow1} );
  font-family: Circular, Helvetica, Arial, sans-serif;
  font-size: 50px;
  font-weight: bold;
  text-transform: uppercase;
}

Thanks in advance for taking a look


Solution

  • I believe it's just a syntax error. You can pass in the variables in directly.

    Please see the codepen

    $hd-color1: #366dbd;    // heading color
    $hd-shadow1: 0.24;      // text shadow opacity
    
    @mixin ColorAndTextShadow($color, $opacity) {
      color: $color;
      text-shadow: 3px 1px rgba($color, $opacity );
    }
    
    h2 {
      @include ColorAndTextShadow ( $hd-color1, $hd-shadow1 );
      font-family: Circular, Helvetica, Arial, sans-serif;
      font-size: 50px;
      font-weight: bold;
      text-transform: uppercase;
    }