---
id: bad87fee1348bd9aedf08746
title: Inherit Styles from the Body Element
challengeType: 0
videoUrl: 'https://scrimba.com/c/c9bmdtR'
forumTopicId: 18204
localeTitle: 从 Body 元素继承样式
---
## Description
我们已经证明每一个 HTML 页面都含有body
元素,body
元素也可以使用 CSS 样式。
设置body
元素的样式的方式跟设置其他 HTML 元素的样式一样,并且其他元素也会继承到body
设置的样式。
## Instructions
首先,创建一个文本内容为Hello World
的h1
标签元素。
接着,在body
CSS 规则里面添加一句color: green;
,改变页面其他元素的字体颜色为green(绿色)
。
最后,同样在body
CSS 规则里面添加font-family: monospace;
,设置其他元素字体为font-family: monospace;
。
## Tests
```yml
tests:
- text: '创建一个h1
元素。'
testString: assert(($("h1").length > 0));
- text: 'h1
元素的文本内容应该为Hello World
。'
testString: assert(($("h1").length > 0 && $("h1").text().match(/hello world/i)));
- text: '确保h1
元素具有结束标记。'
testString: assert(code.match(/<\/h1>/g) && code.match(//g).length === code.match(/h1元素具有结束标记。');
- text: 'body
元素的color
属性值应为green
。'
testString: assert(($("body").css("color") === "rgb(0, 128, 0)"));
- text: 'body
元素的font-family
属性值应为monospace
。'
testString: assert(($("body").css("font-family").match(/monospace/i)));
- text: 'h1
元素应该继承body
的monospace
字体属性。'
testString: assert(($("h1").length > 0 && $("h1").css("font-family").match(/monospace/i)));
- text: 'h1
元素的字体颜色也应该继承body
元素的绿色。'
testString: assert(($("h1").length > 0 && $("h1").css("color") === "rgb(0, 128, 0)"));
```
## Challenge Seed
## Solution
```html
// solution required
```