2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf08736
|
|
|
|
title: Style the HTML Body Element
|
|
|
|
challengeType: 0
|
2019-12-13 13:47:57 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/cB77PHW'
|
|
|
|
forumTopicId: 18313
|
2020-01-08 12:40:17 +08:00
|
|
|
localeTitle: 给 HTML 的 Body 元素添加样式
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2019-12-13 13:47:57 +08:00
|
|
|
<section id='description'>
|
|
|
|
现在让我们来讨论一下 CSS 继承。
|
|
|
|
每一个 HTML 页面都含有一个<code>body</code>元素。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2019-12-13 13:47:57 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
我们可以通过设置<code>background-color</code>为<code>black</code>,来证明<code>body</code>元素的存在。
|
|
|
|
添加以下的代码到<code>style</code>标签里面:
|
|
|
|
|
|
|
|
```css
|
|
|
|
body {
|
|
|
|
background-color: black;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2019-12-13 13:47:57 +08:00
|
|
|
- text: '<code>body</code>元素的<code>background-color</code>应该是黑色的。'
|
2020-01-08 12:40:17 +08:00
|
|
|
testString: assert($("body").css("background-color") === "rgb(0, 0, 0)");
|
|
|
|
- text: '确保 CSS 规则格式书写正确,需要开关大括号。'
|
|
|
|
testString: 'assert(code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i));'
|
|
|
|
- text: '确保 CSS 规则要以分号结尾。'
|
|
|
|
testString: 'assert(code.match(/<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i));'
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
|
|
|
|
</style>
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
2019-12-13 13:47:57 +08:00
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
// solution required
|
|
|
|
```
|
2019-12-13 13:47:57 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</section>
|
2019-12-13 13:47:57 +08:00
|
|
|
|