Creating or referencing variables dynamically in Sass

后端 未结 6 1844
臣服心动
臣服心动 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 01:55

    To make a dynamic variable is not possible in SASS as of now, since you will be adding/connecting another var that needs to be parsed once when you run the sass command.

    As soon as the command runs, it will throw an error for Invalid CSS, since all your declared variables will follow hoisting.

    Once run, you can't declare variables again on the fly

    To know that I have understood this, kindly state if the following is correct:

    you want to declare variables where the next part (word) is dynamic

    something like

    $list: 100 200 300;
    
    @each $n in $list {
        $font-$n: normal $n 12px/1 Arial;
    }
    
    // should result in something like
    
    $font-100: normal 100 12px/1 Arial;
    $font-200: normal 200 12px/1 Arial;
    $font-300: normal 300 12px/1 Arial;
    
    // So that we can use it as follows when needed
    
    .span {
        font: $font-200;
        p {
           font: $font-100
        }
    }
    

    If this is what you want, I am afraid as of now, this is not allowed

提交回复
热议问题