Sass - 用另一个变量分配变量 [英] Sass - Assign variable with another variable

查看:63
本文介绍了Sass - 用另一个变量分配变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个变量:

$color_pr1: #d6ad3f;

现在,我正在使用 Gumby,它使用它自己的设置表,其中设置了以下内容:

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

$header-font-color: #55636b !default;

是否可以使用 $color_pr1 代替?像这样吗?

Is it possible to use $color_pr1 instead? Like this?

$header-font-color: $color_pr1; ?

如果现在,我想这一切都错了吗?我想拥有自己的一组颜色等,并在我的项目中重复使用这些颜色.

If now, am I thinking about this all wrong? I'd like to have my own set of colors etc and reuse those within my project.

推荐答案

来自文档:http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variable_defaults_

如果变量尚未分配,您可以通过添加来分配给变量!default 标志到值的末尾.这意味着,如果变量已经被赋值,它不会被重新赋值,但是如果它还没有值,它会被赋予一个.

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.

例如:

$content: "First content";
$content: "Second content?" !default;
$new_content: "First time reference" !default;

#main {
  content: $content;
  new-content: $new_content;
}

被编译为:

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

带有空值的变量被 !default 视为未赋值:

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

$content: null;
$content: "Non-null content" !default;

#main {
  content: $content;
}

被编译为:

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

这篇关于Sass - 用另一个变量分配变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆