--- id: 5a9d727a424fe3d0e10cad12 title: Use a custom CSS Variable challengeType: 0 videoUrl: 'https://scrimba.com/c/cM989ck' forumTopicId: 301090 localeTitle: 使用一个自定义的 CSS 变量 --- ## Description
创建变量后,CSS 属性可以通过引用变量名来使用它的值。 ```css background: var(--penguin-skin); ``` 因为引用了--penguin-skin变量的值,使用了这个样式的元素背景颜色会是灰色。 注意:如果变量名不匹配,样式不会生效。
## Instructions
penguin-toppenguin-bottomright-handleft-handclass 的background属性均使用--penguin-skin变量值。
## Tests
```yml tests: - text: 'penguin-top class 的background属性应使用--penguin-skin变量值。' testString: 'assert(code.match(/.penguin-top\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.penguin-bottom\s{/gi));' - text: 'penguin-bottom class 的background属性应使用--penguin-skin变量值。' testString: 'assert(code.match(/.penguin-bottom\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.right-hand\s{/gi));' - text: 'right-hand class 的background属性应使用--penguin-skin变量值。' testString: 'assert(code.match(/.right-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}[\s\S]*.left-hand\s{/gi));' - text: 'left-hand class 的background属性应使用--penguin-skin变量值。' testString: 'assert(code.match(/.left-hand\s*?{[\s\S]*background\s*?:\s*?var\s*?\(\s*?--penguin-skin\s*?\)\s*?;[\s\S]*}/gi));' ```
## Challenge Seed
```html
```
## Solution
```js // solution required ```