let
和const
关键字定义的。在 Sass 中,变量以$
开头的,后跟变量名。
这里有几个例子:
```scss
$main-fonts: Arial, sans-serif;
$headings-color: green;
//To use variables:
h1 {
font-family: $main-fonts;
color: $headings-color;
}
```
当需要把多个元素设置成相同颜色时,变量就会很有用。一旦我们需要更改颜色,只需要改变这个变量的值就好。
$text-color
并将其设置为红色。然后更改.blog-post
和h2
的color
属性的值为$text-color
变量。
$text-color
声明一个值为红色的 Sass 变量。
testString: assert(code.match(/\$text-color:\s*?red;/g));
- text: 你应使用$text-color
变量来更改.blog-post
和h2
的颜色
。
testString: assert(code.match(/color:\s*?\$text-color;/g));
- text: .blog-post
元素应为红色。
testString: assert($('.blog-post').css('color') == 'rgb(255, 0, 0)');
- text: h2
元素应为红色。
testString: assert($('h2').css('color') == 'rgb(255, 0, 0)');
```
This is a paragraph with some random text in it
Here is some more random text.
Even more random text within a paragraph
This is a paragraph with some random text in it
Here is some more random text.
Even more random text within a paragraph