Search code examples
cssvariablessassmixins

Using a Sass variable called like a mixin


In Sass, I'm not sure what to search for. I want something like:

$dark = function($perc) {
    $decimal = $perc/100%;
    return rgba(0,0,0,$decimal);
}
.bar { box-shadow: 1px 1px 3px $dark(40%); }

So... call a variable like a @mixin? I don't know. I'm sure this is doable, I just don't know how or how to research it.


Solution

  • In SASS those are simply called functions. In your case this would be

    @function dark($percent) {
       @return rgba(0,0,0, $percent / 100);
    }
    

    You can then use it like so

    .bar { box-shadow: 1px 1px 3px dark(40); }