Sass - Assign variable with another variable

后端 未结 2 458
闹比i
闹比i 2021-01-11 14:02

I have this variable:

$color_pr1: #d6ad3f;

Now, I\'m using Gumby and it uses it\'s own settings sheet where the following is set:



        
2条回答
  •  旧巷少年郎
    2021-01-11 14:45

    From the docs: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variable_defaults_

    You can assign to variables if they aren’t already assigned by adding the !default flag to the end of the value. This means that if the variable has already been assigned to, it won’t be re-assigned, but if it doesn’t have a value yet, it will be given one.

    For example:

    $content: "First content";
    $content: "Second content?" !default;
    $new_content: "First time reference" !default;
    
    #main {
      content: $content;
      new-content: $new_content;
    }
    

    is compiled to:

    #main {
      content: "First content";
      new-content: "First time reference"; }
    

    Variables with null values are treated as unassigned by !default:

    $content: null;
    $content: "Non-null content" !default;
    
    #main {
      content: $content;
    }
    

    is compiled to:

    #main {
      content: "Non-null content"; }
    

提交回复
热议问题