2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d7787367417b2b2512aa1
|
2021-01-08 19:20:48 +00:00
|
|
|
title: 使用 header 元素来让屏幕阅读器更容易进行导航
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2020-02-11 09:06:41 +00:00
|
|
|
videoUrl: 'https://scrimba.com/c/cB76vtv'
|
|
|
|
forumTopicId: 301023
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: make-screen-reader-navigation-easier-with-the-header-landmark
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`header` 也是一个具有语义化的、可以提升页面可访问性的 HTML5 标签。 它可以为父级标签呈现简介信息或者导航链接,适用于那些在多个页面顶部重复出现的内容。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
与 `main` 类似,`header` 的语义化特性也可以让辅助工具快速定位到它的内容。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
**注意:**`header` 应当在 HTML 文档的 `body` 标签内使用。 请注意,这个标签与包含页面标题、元信息的 `head` 标签本不相同。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Camper Cat 正在创作一些训练忍者的精彩文章,并打算为这些文章创建一个新的页面。 请把包含 `h1` 的 `div` 标签替换为 `header` 标签。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
应该存在一个 `header` 标签。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('header').length == 1);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`header` 标签中应包含 `h1`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('header').children('h1').length == 1);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
不应存在 `div` 标签。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('div').length == 0);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
确保 `header` 标签是闭合的。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(/<\/header>/g) &&
|
|
|
|
code.match(/<\/header>/g).length === code.match(/<header>/g).length
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-02-11 09:06:41 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<h1>Training with Camper Cat</h1>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<main>
|
|
|
|
<section id="stealth">
|
|
|
|
<h2>Stealth & Agility Training</h2>
|
|
|
|
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
|
|
|
|
<article><h3>No training is NP-complete without parkour</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="combat">
|
|
|
|
<h2>Combat Training</h2>
|
|
|
|
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
|
|
|
|
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="weapons">
|
|
|
|
<h2>Weapons Training</h2>
|
|
|
|
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
|
|
|
|
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<header>
|
|
|
|
<h1>Training with Camper Cat</h1>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<main>
|
|
|
|
<section id="stealth">
|
|
|
|
<h2>Stealth & Agility Training</h2>
|
|
|
|
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
|
|
|
|
<article><h3>No training is NP-complete without parkour</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="combat">
|
|
|
|
<h2>Combat Training</h2>
|
|
|
|
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
|
|
|
|
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="weapons">
|
|
|
|
<h2>Weapons Training</h2>
|
|
|
|
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
|
|
|
|
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
```
|