let
和const
关键字定义变量。在Sass中,变量以$
开头,后跟变量名。以下是几个例子: $ main-fonts:Arial,sans-serif;变量有用的一个例子是当许多元素需要是相同的颜色时。如果更改了该颜色,则编辑代码的唯一位置是变量值。
$ headings-color:green;
//使用变量:
h1 {
font-family:$ main-fonts;
颜色:$ headings-color;
}
$text-color
并将其设置为红色。然后将.blog-post
和h2
的color
属性值更改为$text-color
变量。 $text-color
声明的Sass变量,其值为red。
testString: 'assert(code.match(/\$text-color:\s*?red;/g), "Your code should have a Sass variable declared for $text-color
with a value of red.");'
- text: 您的代码应使用$text-color
变量来更改.blog-post
和h2
项的color
。
testString: 'assert(code.match(/color:\s*?\$text-color;/g), "Your code should use the $text-color
variable to change the color
for the .blog-post
and h2
items.");'
- text: 您的.blog-post
元素应该是红色。
testString: 'assert($(".blog-post").css("color") == "rgb(255, 0, 0)", "Your .blog-post
element should have a color of red.");'
- text: 你的h2
元素应该是红色。
testString: 'assert($("h2").css("color") == "rgb(255, 0, 0)", "Your h2
elements should have a color of red.");'
```
This is a paragraph with some random text in it
Here is some more random text.
Even more random text within a paragraph