Creating or referencing variables dynamically in Sass

后端 未结 6 1780
臣服心动
臣服心动 2020-11-22 01:31

I\'m trying to use string interpolation on my variable to reference another variable:

// Set up variable and mixin
$         


        
6条回答
  •  无人及你
    2020-11-22 02:05

    Anytime I need to use a conditional value, I lean on functions. Here's a simple example.

    $foo: 2em;
    $bar: 1.5em;
    
    @function foo-or-bar($value) {
      @if $value == "foo" {
        @return $foo;
      }
      @else {
        @return $bar;
      }
    }
    
    @mixin do-this($thing) {
      width: foo-or-bar($thing);
    }
    

提交回复
热议问题