Search code examples
cssvariablessassapostrophe

SCSS variable content inside apostrophes


@mixin f1($color1, $color2){
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='$color1', endColorstr='$color2',GradientType=0);
}

What i want to do is escape the apostrophe's ability of turning $color1 into a string. startColorstr='$color1' into startColor1str='#000000'.

@mixin f1($color1, $color2){
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=+"'"+$color1+"'"+, endColorstr=+"'"+$color2+"'"+,GradientType=0);
}

this didnt work


Solution

  • apparently i had to add the variable inside brackets like '{$color}' but still that wouldnt work alone. i had to also add a '#' (hash) as well like '#{$color}' (even though i was passing the value of "#333" in the mixin, it still required the #

    So the result looks something like this:

    @mixin f1($color1,$color2){
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$color1}', endColorstr='#{$color2}',GradientType=0);
    }