chore(learn): Applied MDX format to Chinese curriculum files (#40462)
This commit is contained in:
@ -1,59 +1,32 @@
|
||||
---
|
||||
id: 587d774c367417b2b2512a9c
|
||||
title: 为视觉障碍用户添加替代图像的文本
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cPp7VfD'
|
||||
forumTopicId: 16628
|
||||
title: 为视觉障碍用户添加替代图像的文本
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
在其他挑战里你应该已经见到过<code>img</code>标签的<code>alt</code>属性了。<code>alt</code>属性中的文本作为备用文字描述了图片的内容,这可以帮助用户在图片加载失败或者不可见的情况下理解图片内容,也有助于搜索引擎理解图片内容,并将其加入到搜索结果中。例如:
|
||||
<code><img src="importantLogo.jpeg" alt="Company logo"></code>
|
||||
视觉障碍用户无法通过视觉获取信息,而是通过屏幕阅读器将网页内容转换为音频以获取信息。屏幕阅读器可以识别<code>alt</code>属性,朗读其中的内容,来告知用户图片包含的关键信息。
|
||||
良好的<code>alt</code>文本可以简明扼要地描述图片信息,所以你应该为图片添加<code>alt</code>属性。另外,HTML5 标准也在考虑强制要求对图片添加<code>alt</code>属性。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
在其他挑战里你应该已经见到过`img`标签的`alt`属性了。`alt`属性中的文本作为备用文字描述了图片的内容,这可以帮助用户在图片加载失败或者不可见的情况下理解图片内容,也有助于搜索引擎理解图片内容,并将其加入到搜索结果中。例如:
|
||||
|
||||
碰巧,Camper Cat 是忍者中写代码最厉害的,他正在建立一个可以分享忍者知识的网站。在这个网站中,他使用一张简介图片来展示技能。给<code>img</code>标签添加一个<code>alt</code>属性,说明 Camper Cat 在学习空手道(图片的<code>src</code>属性没有指向任何链接,因此你可以看到<code>alt</code>属性中的文本)。
|
||||
`<img src="importantLogo.jpeg" alt="Company logo">`
|
||||
|
||||
</section>
|
||||
视觉障碍用户无法通过视觉获取信息,而是通过屏幕阅读器将网页内容转换为音频以获取信息。屏幕阅读器可以识别`alt`属性,朗读其中的内容,来告知用户图片包含的关键信息。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
良好的`alt`文本可以简明扼要地描述图片信息,所以你应该为图片添加`alt`属性。另外,HTML5 标准也在考虑强制要求对图片添加`alt`属性。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的<code>img</code>标签应该包含一个非空的<code>alt</code>属性。'
|
||||
testString: assert($('img').attr('alt'));
|
||||
# --instructions--
|
||||
|
||||
碰巧,Camper Cat 是忍者中写代码最厉害的,他正在建立一个可以分享忍者知识的网站。在这个网站中,他使用一张简介图片来展示技能。给`img`标签添加一个`alt`属性,说明 Camper Cat 在学习空手道(图片的`src`属性没有指向任何链接,因此你可以看到`alt`属性中的文本)。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的`img`标签应该包含一个非空的`alt`属性。
|
||||
|
||||
```js
|
||||
assert($('img').attr('alt'));
|
||||
```
|
||||
|
||||
</section>
|
||||
# --solutions--
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<img src="doingKarateWow.jpeg">
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,16 +1,19 @@
|
||||
---
|
||||
id: 587d778b367417b2b2512aa8
|
||||
title: 添加可访问的日期选择器
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cR3bRbCV'
|
||||
forumTopicId: 301008
|
||||
title: 添加可访问的日期选择器
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
表单中经常出现<code>input</code>标签,它可以用来创建多种表单控件。它的<code>type</code>属性指定了所要创建的<code>input</code>标签类型。
|
||||
在以前的挑战中,你可能已经见过<code>text</code>与<code>submit</code>类型的<code>input</code>标签,HTML5 引入了<code>date</code>类型来创建时间选择器。依赖于浏览器的支持,当点击<code>input</code>标签时,时间选择器会显示出来,这可以让用户填写表单更加容易。
|
||||
对于旧版本的浏览器,<code>type</code>属性的默认值是<code>text</code>。这种情况下,可以利用<code>label</code>标签或者占位文本来提示用户<code>input</code>标签的输入类型为日期。
|
||||
# --description--
|
||||
|
||||
表单中经常出现`input`标签,它可以用来创建多种表单控件。它的`type`属性指定了所要创建的`input`标签类型。
|
||||
|
||||
在以前的挑战中,你可能已经见过`text`与`submit`类型的`input`标签,HTML5 引入了`date`类型来创建时间选择器。依赖于浏览器的支持,当点击`input`标签时,时间选择器会显示出来,这可以让用户填写表单更加容易。
|
||||
|
||||
对于旧版本的浏览器,`type`属性的默认值是`text`。这种情况下,可以利用`label`标签或者占位文本来提示用户`input`标签的输入类型为日期。
|
||||
|
||||
举个例子:
|
||||
|
||||
```html
|
||||
@ -18,74 +21,35 @@ title: 添加可访问的日期选择器
|
||||
<input type="date" id="input1" name="input1">
|
||||
```
|
||||
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 想举办一场比武大会,他想收集参赛者的最佳参赛时间。请为 Camper Cat 的页面添加一个<code>input</code>标签,其<code>type</code>属性值为 date,<code>id</code>属性为 pickdate,<code>name</code>属性为 date。
|
||||
</section>
|
||||
Camper Cat 想举办一场比武大会,他想收集参赛者的最佳参赛时间。请为 Camper Cat 的页面添加一个`input`标签,其`type`属性值为 date,`id`属性为 pickdate,`name`属性为 date。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码中应该有 1 个<code>input</code>标签。'
|
||||
testString: assert($('input').length == 2);
|
||||
- text: '你的<code>input</code>标签的<code>type</code>属性值应该为 date。'
|
||||
testString: assert($('input').attr('type') == 'date');
|
||||
- text: '你的<code>input</code>标签的<code>id</code>属性值应该为 pickdate。'
|
||||
testString: assert($('input').attr('id') == 'pickdate');
|
||||
- text: '你的<code>input</code>标签的<code>name</code>属性值应该为 date。'
|
||||
testString: assert($('input').attr('name') == 'date');
|
||||
你的代码中应该有 1 个`input`标签。
|
||||
|
||||
```js
|
||||
assert($('input').length == 2);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的`input`标签的`type`属性值应该为 date。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Tournaments</h1>
|
||||
</header>
|
||||
<main>
|
||||
<section>
|
||||
<h2>Mortal Kombat Tournament Survey</h2>
|
||||
<form>
|
||||
<p>Tell us the best date for the competition</p>
|
||||
<label for="pickdate">Preferred Date:</label>
|
||||
|
||||
<!-- Add your code below this line -->
|
||||
|
||||
|
||||
|
||||
<!-- Add your code above this line -->
|
||||
|
||||
<input type="submit" name="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('input').attr('type') == 'date');
|
||||
```
|
||||
|
||||
</div>
|
||||
你的`input`标签的`id`属性值应该为 pickdate。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('input').attr('id') == 'pickdate');
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
你的`input`标签的`name`属性值应该为 date。
|
||||
|
||||
```js
|
||||
assert($('input').attr('name') == 'date');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,71 +1,31 @@
|
||||
---
|
||||
id: 587d778f367417b2b2512aad
|
||||
title: 考虑色盲用户的需求仔细选择传达信息的颜色
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/c437as3'
|
||||
forumTopicId: 301011
|
||||
title: 考虑色盲用户的需求仔细选择传达信息的颜色
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
色盲的形式有很多种,它的表现可以从对特定波长光波的感知度较低,到几乎无法看到颜色。最常见的形式是对绿色的低感知度。
|
||||
|
||||
例如:如果内容的前景色与背景色是两种相近的绿色,那么色盲用户可能会无法识别它们。可以认为色轮上相邻的颜色是相近的,在表示重要信息的时候应避免使用这些颜色的组合。
|
||||
<strong>注意:</strong><br>一些在线颜色拾取器有色盲模拟功能,可以模拟颜色在不同形式色盲的视觉中的呈现结果,它们和在线对比度检查器一样,都是很好的工具。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 正在测试一个重要按钮的不同样式。在色轮上,黄色(<code>#FFFF33</code>)的<code>background-color</code>和绿色(<code>#33FF33</code>)的文本<code>color</code>是相邻的色调,一些色盲用户几乎无法区分它们,而且这两个颜色的亮度相近,对比度太小。为了解决这两个问题,请将文本的<code>color</code>修改为深蓝色(<code>#003366</code>)。
|
||||
</section>
|
||||
**注意:**
|
||||
一些在线颜色拾取器有色盲模拟功能,可以模拟颜色在不同形式色盲的视觉中的呈现结果,它们和在线对比度检查器一样,都是很好的工具。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>button</code>的文本<code>color</code>应该是深蓝色。'
|
||||
testString: assert($('button').css('color') == 'rgb(0, 51, 102)');
|
||||
Camper Cat 正在测试一个重要按钮的不同样式。在色轮上,黄色(`#FFFF33`)的`background-color`和绿色(`#33FF33`)的文本`color`是相邻的色调,一些色盲用户几乎无法区分它们,而且这两个颜色的亮度相近,对比度太小。为了解决这两个问题,请将文本的`color`修改为深蓝色(`#003366`)。
|
||||
|
||||
# --hints--
|
||||
|
||||
`button`的文本`color`应该是深蓝色。
|
||||
|
||||
```js
|
||||
assert($('button').css('color') == 'rgb(0, 51, 102)');
|
||||
```
|
||||
|
||||
</section>
|
||||
# --solutions--
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<head>
|
||||
<style>
|
||||
button {
|
||||
color: #33FF33;
|
||||
background-color: #FFFF33;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Danger!</h1>
|
||||
</header>
|
||||
<button>Delete Internet</button>
|
||||
</body>
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,76 +1,38 @@
|
||||
---
|
||||
id: 587d778f367417b2b2512aac
|
||||
title: 考虑色盲用户的需求设置合适的对比度
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cmzMEUw'
|
||||
forumTopicId: 301012
|
||||
title: 考虑色盲用户的需求设置合适的对比度
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
颜色是可视化设计的重要组成部分,但是使用颜色也引入了两个可访问性问题。首先,不能仅仅使用颜色作为传达重要信息的唯一方式,因为屏幕阅读器无法获取这些信息。其次,前景色与背景色需要有足够的对比度,这样色盲用户才可以识别它们。
|
||||
|
||||
在之前的挑战中,我们用文本备用方案解决了第一个问题。在上一个挑战中,我们使用对比度检测工具解决了第二问题。WCAG 建议为颜色及灰度组合使用 4.5 : 1 的对比度。
|
||||
|
||||
色盲用户无法将一些颜色与另一些颜色区分出来——通常是因为色调,也有时候是因为亮度。你可能想起对比度是用前景色与背景色的相对亮度计算的。
|
||||
|
||||
实践中,在对比度检测工具的帮助下,我们可以通过将较暗的颜色变暗、将较淡的颜色变淡的方法来使对比度达到 4.5 : 1。在色轮中,较暗的颜色通常是蓝色、紫色、洋红和红色,而较淡的颜色通常是橙色、黄色、绿色和蓝绿色。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 正在尝试为他的博客文本与背景使用颜色,但是他目前使用的组合是绿色的<code>background-color</code>与栗色的<code>color</code>,它们的对比度为 2.5 : 1。Camper Cat 使用了 CSS 的<code>hsl()</code>(hsl 为 hue, saturation, lightness 的缩写)属性来设置颜色,所以通过修改<code>hsl()</code>属性的第三个参数,可以很容易地调整颜色的亮度。请将<code>background-color</code>的亮度从 35% 增加到 55%,<code>color</code>的亮度从 20% 减少到 15%,这样可以使对比度达到 5.9 : 1。
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
Camper Cat 正在尝试为他的博客文本与背景使用颜色,但是他目前使用的组合是绿色的`background-color`与栗色的`color`,它们的对比度为 2.5 : 1。Camper Cat 使用了 CSS 的`hsl()`(hsl 为 hue, saturation, lightness 的缩写)属性来设置颜色,所以通过修改`hsl()`属性的第三个参数,可以很容易地调整颜色的亮度。请将`background-color`的亮度从 35% 增加到 55%,`color`的亮度从 20% 减少到 15%,这样可以使对比度达到 5.9 : 1。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你应该将<code>color</code>属性的亮度值设置为 15%。'
|
||||
testString: assert(code.match(/color:\s*?hsl\(0,\s*?55%,\s*?15%\)/gi));
|
||||
- text: '你应该将<code>background-color</code>属性的亮度值设置为 55%。'
|
||||
testString: assert(code.match(/background-color:\s*?hsl\(120,\s*?25%,\s*?55%\)/gi));
|
||||
# --hints--
|
||||
|
||||
你应该将`color`属性的亮度值设置为 15%。
|
||||
|
||||
```js
|
||||
assert(code.match(/color:\s*?hsl\(0,\s*?55%,\s*?15%\)/gi));
|
||||
```
|
||||
|
||||
</section>
|
||||
你应该将`background-color`属性的亮度值设置为 55%。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
color: hsl(0, 55%, 20%);
|
||||
background-color: hsl(120, 25%, 35%);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<article>
|
||||
<h2>A Word on the Recent Catnip Doping Scandal</h2>
|
||||
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
|
||||
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
|
||||
</article>
|
||||
</body>
|
||||
```js
|
||||
assert(code.match(/background-color:\s*?hsl\(120,\s*?25%,\s*?55%\)/gi));
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,67 +1,47 @@
|
||||
---
|
||||
id: 587d778f367417b2b2512aae
|
||||
title: 使用描述性链接文本赋予链接含义
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/c437DcV'
|
||||
forumTopicId: 301013
|
||||
title: 使用描述性链接文本赋予链接含义
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
屏幕阅读器用户可以选择其设备读取的内容的类型,这包括跳转到(或跳过)标志标签,跳转到主要内容,或者从标题中获取页面摘要,还可以选择只听取页面中的有效链接。
|
||||
屏幕阅读器通过阅读链接文本或者锚点标签(<code>a</code>)之间的内容来完成这个操作。使用 "click here" 或者 "read more" 作为链接文本并没有多少帮助。相反地,应该在<code>a</code>标签中使用简洁的描述性语言来为用户提供更多的信息。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 在链接中使用的文本在脱离上下文的情况下,描述性不是很好。请修改锚点标签(<code>a</code>),将其包含的文本从 "click here" 改为 "information about batteries"。
|
||||
</section>
|
||||
屏幕阅读器通过阅读链接文本或者锚点标签(`a`)之间的内容来完成这个操作。使用 "click here" 或者 "read more" 作为链接文本并没有多少帮助。相反地,应该在`a`标签中使用简洁的描述性语言来为用户提供更多的信息。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '请修改<code>a</code>标签,将其包含的文本从 "click here" 改为 "information about batteries"。'
|
||||
testString: assert($('a').text().match(/^(information about batteries)$/g));
|
||||
- text: '<code>a</code>元素应该有一个<code>href</code>属性,且值为空字符串'
|
||||
testString: assert($('a').attr('href') === '');
|
||||
- text: '<code>a</code> 元素应该有一个结束标记'
|
||||
testString: assert(code.match(/<\/a>/g) && code.match(/<\/a>/g).length === code.match(/<a href=(''|"")>/g).length);
|
||||
Camper Cat 在链接中使用的文本在脱离上下文的情况下,描述性不是很好。请修改锚点标签(`a`),将其包含的文本从 "click here" 改为 "information about batteries"。
|
||||
|
||||
# --hints--
|
||||
|
||||
请修改`a`标签,将其包含的文本从 "click here" 改为 "information about batteries"。
|
||||
|
||||
```js
|
||||
assert(
|
||||
$('a')
|
||||
.text()
|
||||
.match(/^(information about batteries)$/g)
|
||||
);
|
||||
```
|
||||
|
||||
</section>
|
||||
`a`元素应该有一个`href`属性,且值为空字符串
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<article>
|
||||
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
|
||||
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near. <a href="">Click here</a> for information about batteries</p>
|
||||
</article>
|
||||
</body>
|
||||
```js
|
||||
assert($('a').attr('href') === '');
|
||||
```
|
||||
|
||||
</div>
|
||||
`a` 元素应该有一个结束标记
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/a>/g) &&
|
||||
code.match(/<\/a>/g).length === code.match(/<a href=(''|"")>/g).length
|
||||
);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
---
|
||||
id: 587d7789367417b2b2512aa4
|
||||
title: 使用 audio 元素提高音频内容的可访问性
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cVJVkcZ'
|
||||
forumTopicId: 301014
|
||||
title: 使用 audio 元素提高音频内容的可访问性
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
HTML5 的<code>audio</code>标签用于呈现音频内容,它也具有语义化特性。可以在<code>audio</code>上下文中为音频内容添加文字说明或者字幕链接,使听觉障碍用户也能获取音频中的信息。
|
||||
<code>audio</code>支持<code>controls</code>属性,可以使浏览器为音频提供具有开始、暂停等功能的播放控件。<code>controls</code>属性是一个布尔属性,只要这个属性出现在<code>audio</code>标签中,浏览器就会开启播放控件。
|
||||
# --description--
|
||||
|
||||
HTML5 的`audio`标签用于呈现音频内容,它也具有语义化特性。可以在`audio`上下文中为音频内容添加文字说明或者字幕链接,使听觉障碍用户也能获取音频中的信息。
|
||||
|
||||
`audio`支持`controls`属性,可以使浏览器为音频提供具有开始、暂停等功能的播放控件。`controls`属性是一个布尔属性,只要这个属性出现在`audio`标签中,浏览器就会开启播放控件。
|
||||
|
||||
举个例子:
|
||||
|
||||
```html
|
||||
@ -19,70 +21,65 @@ HTML5 的<code>audio</code>标签用于呈现音频内容,它也具有语义
|
||||
</audio>
|
||||
```
|
||||
|
||||
<strong>注意:</strong><br>多媒体内容通常同时包含音频与视频部分,它需要同步音频与字幕,以使视觉或听觉障碍用户可以获取它的内容。一般情况下,网页开发者不需要创建音频与字幕,但是需要将它们添加到多媒体中。
|
||||
</section>
|
||||
**注意:**
|
||||
多媒体内容通常同时包含音频与视频部分,它需要同步音频与字幕,以使视觉或听觉障碍用户可以获取它的内容。一般情况下,网页开发者不需要创建音频与字幕,但是需要将它们添加到多媒体中。
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
是时候让 Camper Cat 休息一下,并与朋友 camper Zersiax (@zersiax) 会面。Zersiax 是一位屏幕阅读器用户,同时也是无障碍设计的高手。为了体验 Zersiax 的屏幕阅读器的朗读效果,请在<code>p</code>标签之后添加一个具有<code>controls</code>属性的<code>audio</code>标签。然后在<code>audio</code>标签内添加一个<code>source</code>标签,并且设置<code>src</code>属性为"https://s3.amazonaws.com/freecodecamp/screen-reader.mp3",并且设置<code>type</code>属性为"audio/mpeg".
|
||||
<strong>注意:</strong><br>音频片段的播放速度可能会快到另我们难以理解,但是对于屏幕阅读器用户来说这是正常速度。
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
是时候让 Camper Cat 休息一下,并与朋友 camper Zersiax (@zersiax) 会面。Zersiax 是一位屏幕阅读器用户,同时也是无障碍设计的高手。为了体验 Zersiax 的屏幕阅读器的朗读效果,请在`p`标签之后添加一个具有`controls`属性的`audio`标签。然后在`audio`标签内添加一个`source`标签,并且设置`src`属性为"`https://s3.amazonaws.com/freecodecamp/screen-reader.mp3`",并且设置`type`属性为"audio/mpeg".
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该包含一个<code>audio</code>标签。'
|
||||
testString: assert($('audio').length === 1);
|
||||
- text: '确保你的<code>audio</code>标签是闭合的。'
|
||||
testString: assert(code.match(/<\/audio>/g).length === 1 && code.match(/<audio.*>[\s\S]*<\/audio>/g));
|
||||
- text: '<code>audio</code>标签应具有<code>controls</code>属性。'
|
||||
testString: assert($('audio').attr('controls'));
|
||||
- text: '你的代码应具有<code>source</code>标签。'
|
||||
testString: assert($('source').length === 1);
|
||||
- text: '<code>source</code>标签应该在<code>audio</code>标签中。'
|
||||
testString: assert($('audio').children('source').length === 1);
|
||||
- text: '<code>source</code>标签中<code>src</code>属性的值应该与教程中的链接一致。'
|
||||
testString: assert($('source').attr('src') === 'https://s3.amazonaws.com/freecodecamp/screen-reader.mp3');
|
||||
- text: '<code>source</code>标签中应具有<code>type</code>属性,其值为 audio/mpeg。'
|
||||
testString: assert($('source').attr('type') === 'audio/mpeg');
|
||||
**注意:**
|
||||
音频片段的播放速度可能会快到另我们难以理解,但是对于屏幕阅读器用户来说这是正常速度。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码应该包含一个`audio`标签。
|
||||
|
||||
```js
|
||||
assert($('audio').length === 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
确保你的`audio`标签是闭合的。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Real Coding Ninjas</h1>
|
||||
</header>
|
||||
<main>
|
||||
<p>A sound clip of Zersiax's screen reader in action.</p>
|
||||
|
||||
|
||||
|
||||
</main>
|
||||
</body>
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/audio>/g).length === 1 &&
|
||||
code.match(/<audio.*>[\s\S]*<\/audio>/g)
|
||||
);
|
||||
```
|
||||
|
||||
</div>
|
||||
`audio`标签应具有`controls`属性。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('audio').attr('controls'));
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
你的代码应具有`source`标签。
|
||||
|
||||
```js
|
||||
assert($('source').length === 1);
|
||||
```
|
||||
|
||||
`source`标签应该在`audio`标签中。
|
||||
|
||||
```js
|
||||
assert($('audio').children('source').length === 1);
|
||||
```
|
||||
|
||||
`source`标签中`src`属性的值应该与教程中的链接一致。
|
||||
|
||||
```js
|
||||
assert(
|
||||
$('source').attr('src') ===
|
||||
'https://s3.amazonaws.com/freecodecamp/screen-reader.mp3'
|
||||
);
|
||||
```
|
||||
|
||||
`source`标签中应具有`type`属性,其值为 audio/mpeg。
|
||||
|
||||
```js
|
||||
assert($('source').attr('type') === 'audio/mpeg');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
---
|
||||
id: 587d778a367417b2b2512aa5
|
||||
title: 使用 figure 元素提高图表的可访问性
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cGJMqtE'
|
||||
forumTopicId: 301015
|
||||
title: 使用 figure 元素提高图表的可访问性
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
HTML5 引入了<code>figure</code>标签以及与之相关的<code>figcaption</code>标签。它们一起用于展示可视化信息(如:图片、图表)及其标题。这样通过语义化对内容进行分组并配以用于解释<code>figure</code>的文字,可以极大地提升内容的可访问性。
|
||||
# --description--
|
||||
|
||||
HTML5 引入了`figure`标签以及与之相关的`figcaption`标签。它们一起用于展示可视化信息(如:图片、图表)及其标题。这样通过语义化对内容进行分组并配以用于解释`figure`的文字,可以极大地提升内容的可访问性。
|
||||
|
||||
对于图表之类的可视化数据,标题可以为屏幕阅读器用户提供简要的说明。但是这里有一个难点,如何处理那些超出屏幕可视范围(使用 CSS)的表格版本的图表数据,以使屏幕阅读器用户也可以获取信息。
|
||||
举个例子——注意<code>figcaption</code>包含在<code>figure</code>标签中,并且可以与其他标签组合使用:
|
||||
|
||||
举个例子——注意`figcaption`包含在`figure`标签中,并且可以与其他标签组合使用:
|
||||
|
||||
```html
|
||||
<figure>
|
||||
@ -22,96 +24,50 @@ HTML5 引入了<code>figure</code>标签以及与之相关的<code>figcaption</c
|
||||
</figure>
|
||||
```
|
||||
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 正在努力创建一张条形图,用来显示每周用于隐形、战斗、武器训练的时间。请帮助完善他的页面,将他的用于呈现图表的<code>div</code>标签修改为<code>figure</code>标签,用于呈现图表标题的<code>p</code>标签改为<code>figcaption</code>标签。
|
||||
</section>
|
||||
Camper Cat 正在努力创建一张条形图,用来显示每周用于隐形、战斗、武器训练的时间。请帮助完善他的页面,将他的用于呈现图表的`div`标签修改为`figure`标签,用于呈现图表标题的`p`标签改为`figcaption`标签。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该有 1 个<code>figure</code>标签。'
|
||||
testString: assert($('figure').length == 1);
|
||||
- text: '你的代码应该有 1 个<code>figcaption</code>标签。'
|
||||
testString: assert($('figcaption').length == 1);
|
||||
- text: '你的代码不应有<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
- text: '你的代码不应有<code>p</code>标签。'
|
||||
testString: assert($('p').length == 0);
|
||||
- text: '<code>figcaption</code>应该为<code>figure</code>的子标签。'
|
||||
testString: assert($('figure').children('figcaption').length == 1);
|
||||
- text: '请确保你的<code>figure</code>标签是闭合的。'
|
||||
testString: assert(code.match(/<\/figure>/g) && code.match(/<\/figure>/g).length === code.match(/<figure>/g).length);
|
||||
你的代码应该有 1 个`figure`标签。
|
||||
|
||||
```js
|
||||
assert($('figure').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的代码应该有 1 个`figcaption`标签。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Training</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="#stealth">Stealth & Agility</a></li>
|
||||
<li><a href="#combat">Combat</a></li>
|
||||
<li><a href="#weapons">Weapons</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
<section>
|
||||
|
||||
<!-- Add your code below this line -->
|
||||
<div>
|
||||
<!-- Stacked bar chart will go here -->
|
||||
<br>
|
||||
<p>Breakdown per week of time to spend training in stealth, combat, and weapons.</p>
|
||||
</div>
|
||||
<!-- Add your code above this line -->
|
||||
|
||||
</section>
|
||||
<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>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('figcaption').length == 1);
|
||||
```
|
||||
|
||||
</div>
|
||||
你的代码不应有`div`标签。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
你的代码不应有`p`标签。
|
||||
|
||||
```js
|
||||
assert($('p').length == 0);
|
||||
```
|
||||
|
||||
`figcaption`应该为`figure`的子标签。
|
||||
|
||||
```js
|
||||
assert($('figure').children('figcaption').length == 1);
|
||||
```
|
||||
|
||||
请确保你的`figure`标签是闭合的。
|
||||
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/figure>/g) &&
|
||||
code.match(/<\/figure>/g).length === code.match(/<figure>/g).length
|
||||
);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
---
|
||||
id: 587d778a367417b2b2512aa6
|
||||
title: 使用 label 元素提高表单的可访问性
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cGJMMAN'
|
||||
forumTopicId: 301016
|
||||
title: 使用 label 元素提高表单的可访问性
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
合理地使用语义化的 HTML 标签和属性可以提升页面可访问性。在接下来的挑战中,你将会看到使用表单属性的重要场景。
|
||||
<code>label</code>标签用于呈现特定表单控件的文本,通常是选项的名称。这些文本代表了选项的含义,使表单具有更好的可读性。<code>label</code>标签的<code>for</code>属性指定了与<code>label</code>绑定的表单控件,并且屏幕阅读器也会读取<code>for</code>属性。
|
||||
在 HTML 基础章节的课程中,我们已经了解了单选按钮标签。在那节课程中,我们为了可以点击单选按钮的名称,将<code>input</code>标签放在<code>label</code>标签中。在本节课程中,我们介绍了另外一种实现这个功能的方法,那就是使用<code>for</code>属性。
|
||||
<code>for</code>属性的值必须与表单控件的<code>id</code>属性的值相同。举个例子:
|
||||
|
||||
`label`标签用于呈现特定表单控件的文本,通常是选项的名称。这些文本代表了选项的含义,使表单具有更好的可读性。`label`标签的`for`属性指定了与`label`绑定的表单控件,并且屏幕阅读器也会读取`for`属性。
|
||||
|
||||
在 HTML 基础章节的课程中,我们已经了解了单选按钮标签。在那节课程中,我们为了可以点击单选按钮的名称,将`input`标签放在`label`标签中。在本节课程中,我们介绍了另外一种实现这个功能的方法,那就是使用`for`属性。
|
||||
|
||||
`for`属性的值必须与表单控件的`id`属性的值相同。举个例子:
|
||||
|
||||
```html
|
||||
<form>
|
||||
@ -20,79 +23,23 @@ title: 使用 label 元素提高表单的可访问性
|
||||
</form>
|
||||
```
|
||||
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 希望他的博客文章能有很多订阅,他想添加一个电子邮件注册表单。请为表示电子邮件的<code>label</code>标签添加<code>for</code>属性,并设置属性值与<code>input</code>标签的<code>id</code>属性值相同。
|
||||
</section>
|
||||
Camper Cat 希望他的博客文章能有很多订阅,他想添加一个电子邮件注册表单。请为表示电子邮件的`label`标签添加`for`属性,并设置属性值与`input`标签的`id`属性值相同。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的<code>label</code>标签应该有 1 个非空的<code>for</code>属性。'
|
||||
testString: assert($('label').attr('for'));
|
||||
- text: '<code>for</code>属性的值应该与<code>input</code>标签的 id 值 email 相同。'
|
||||
testString: assert($('label').attr('for') == 'email');
|
||||
你的`label`标签应该有 1 个非空的`for`属性。
|
||||
|
||||
```js
|
||||
assert($('label').attr('for'));
|
||||
```
|
||||
|
||||
</section>
|
||||
`for`属性的值应该与`input`标签的 id 值 email 相同。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<section>
|
||||
<form>
|
||||
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
|
||||
|
||||
|
||||
<label>Email:</label>
|
||||
<input type="text" id="email" name="email">
|
||||
|
||||
|
||||
<input type="submit" name="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
<article>
|
||||
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
|
||||
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
|
||||
</article>
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
<article>
|
||||
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
|
||||
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
|
||||
</article>
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
<article>
|
||||
<h2>Is Chuck Norris a Cat Person?</h2>
|
||||
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
|
||||
</article>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('label').attr('for') == 'email');
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,74 +1,34 @@
|
||||
---
|
||||
id: 587d778e367417b2b2512aab
|
||||
title: 使用高对比度文本提高可读性
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cKb3nCq'
|
||||
forumTopicId: 301017
|
||||
title: 使用高对比度文本提高可读性
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
低对比度的前景色与背景色会使文本难以阅读。足够的对比度可以提高内容的可读性,但是怎样的对比度才算是 “足够” 的?
|
||||
|
||||
Web 内容无障碍指南(WCAG)建议正常文本的对比度至少为 4.5 : 1。对比度是通过比较两种颜色的相对亮度值来计算的,其范围是从相同颜色的 1 : 1(无对比度)到白色与黑色的最高对比度 21 : 1。网上有很多可以帮助你计算对比度的工具。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 为他的博客选择了白色背景,浅灰色文字,对比度为 1.5 : 1,这使博客文章难以阅读。请将文字的<code>color</code>从当前的浅灰色(<code>#D3D3D3</code>)修改为深灰色(<code>#636363</code>),以使对比度提升到 6 : 1。
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
Camper Cat 为他的博客选择了白色背景,浅灰色文字,对比度为 1.5 : 1,这使博客文章难以阅读。请将文字的`color`从当前的浅灰色(`#D3D3D3`)修改为深灰色(`#636363`),以使对比度提升到 6 : 1。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你应该将<code>body</code>的<code>color</code>修改为深灰色。'
|
||||
testString: assert($('body').css('color') == 'rgb(99, 99, 99)');
|
||||
- text: '你不应该修改<code>body</code>的<code>background-color</code>。'
|
||||
testString: assert($('body').css('background-color') == 'rgb(255, 255, 255)');
|
||||
# --hints--
|
||||
|
||||
你应该将`body`的`color`修改为深灰色。
|
||||
|
||||
```js
|
||||
assert($('body').css('color') == 'rgb(99, 99, 99)');
|
||||
```
|
||||
|
||||
</section>
|
||||
你不应该修改`body`的`background-color`。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
color: #D3D3D3;
|
||||
background-color: #FFF;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<article>
|
||||
<h2>A Word on the Recent Catnip Doping Scandal</h2>
|
||||
<p>The influence that catnip has on feline behavior is well-documented, and its use as an herbal supplement in competitive ninja circles remains controversial. Once again, the debate to ban the substance is brought to the public's attention after the high-profile win of Kittytron, a long-time proponent and user of the green stuff, at the Claw of Fury tournament.</p>
|
||||
<p>As I've stated in the past, I firmly believe a true ninja's skills must come from within, with no external influences. My own catnip use shall continue as purely recreational.</p>
|
||||
</article>
|
||||
</body>
|
||||
```js
|
||||
assert($('body').css('background-color') == 'rgb(255, 255, 255)');
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,65 +1,38 @@
|
||||
---
|
||||
id: 587d774e367417b2b2512a9f
|
||||
title: 使用 main 元素包裹主题内容
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cPp7zuE'
|
||||
forumTopicId: 301018
|
||||
title: 使用 main 元素包裹主题内容
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
HTML5 添加了诸如<code>main</code>、<code>header</code>、<code>footer</code>、<code>nav</code>、<code>article</code>、<code>section</code>等大量新标签,开发人员提供更多的选择,也兼顾了无障碍特性。
|
||||
默认情况下,浏览器呈现这些新标签的方式与<code>div</code>相似。然而,合理地使用它们,可以使你的标签更加的语义化。辅助技术(如:屏幕阅读器)可以通过这些标签为用户提供更加准确的、易于理解的页面信息。
|
||||
<code>main</code>标签用于呈现网页的主体内容,且每个页面只能有一个。这意味着它只应包含与页面中心主题相关的信息,而不应包含如导航连接、网页横幅等可以在多个页面中重复出现的内容。
|
||||
<code>main</code>标签的语义化特性可以使辅助技术快速定位到页面的主体。 如果页面顶部有一个 “跳转到主要内容” 的链接,那么辅助设备会自动识别<code>main</code>标签,实现这个功能。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 对他的忍者武器页面有一些新的想法,请帮助他在<code>header</code>标签和<code>footer</code>标签(在接下来的挑战中会详细介绍)之间添加完整<code>main</code>标签来使页面语义化。在这个挑战中,你可以先让<code>main</code>为空。
|
||||
</section>
|
||||
HTML5 添加了诸如`main`、`header`、`footer`、`nav`、`article`、`section`等大量新标签,开发人员提供更多的选择,也兼顾了无障碍特性。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
默认情况下,浏览器呈现这些新标签的方式与`div`相似。然而,合理地使用它们,可以使你的标签更加的语义化。辅助技术(如:屏幕阅读器)可以通过这些标签为用户提供更加准确的、易于理解的页面信息。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该有一个<code>main</code>标签。'
|
||||
testString: assert($('main').length == 1);
|
||||
- text: '<code>main</code>标签应该在<code>header</code>标签与<code>footer</code>标签之间。'
|
||||
testString: assert(code.match(/<\/header>\s*?<main>\s*?<\/main>/gi));
|
||||
`main`标签用于呈现网页的主体内容,且每个页面只能有一个。这意味着它只应包含与页面中心主题相关的信息,而不应包含如导航连接、网页横幅等可以在多个页面中重复出现的内容。
|
||||
|
||||
`main`标签的语义化特性可以使辅助技术快速定位到页面的主体。 如果页面顶部有一个 “跳转到主要内容” 的链接,那么辅助设备会自动识别`main`标签,实现这个功能。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 对他的忍者武器页面有一些新的想法,请帮助他在`header`标签和`footer`标签(在接下来的挑战中会详细介绍)之间添加完整`main`标签来使页面语义化。在这个挑战中,你可以先让`main`为空。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码应该有一个`main`标签。
|
||||
|
||||
```js
|
||||
assert($('main').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
`main`标签应该在`header`标签与`footer`标签之间。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<header>
|
||||
<h1>Weapons of the Ninja</h1>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<footer></footer>
|
||||
```js
|
||||
assert(code.match(/<\/header>\s*?<main>\s*?<\/main>/gi));
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,71 +1,41 @@
|
||||
---
|
||||
id: 587d774c367417b2b2512a9d
|
||||
title: 知道 Alt 文本何时应该留空
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cM9P4t2'
|
||||
forumTopicId: 301019
|
||||
title: 知道 Alt 文本何时应该留空
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
在上一个挑战中,我们了解到<code>img</code>标签必须有一个<code>alt</code>属性。在图片已经有了文字说明,或者仅仅为了美化页面的情况下,<code>alt</code>属性似乎有些多余。
|
||||
即便如此,我们仍然需要为<code>img</code>标签添加<code>alt</code>属性,这时可以把它设为空,例如:
|
||||
<code><img src="visualDecoration.jpeg" alt=""></code>
|
||||
# --description--
|
||||
|
||||
在上一个挑战中,我们了解到`img`标签必须有一个`alt`属性。在图片已经有了文字说明,或者仅仅为了美化页面的情况下,`alt`属性似乎有些多余。
|
||||
|
||||
即便如此,我们仍然需要为`img`标签添加`alt`属性,这时可以把它设为空,例如:
|
||||
|
||||
`<img src="visualDecoration.jpeg" alt="">`
|
||||
|
||||
背景图片通常起装饰作用,而且含有 CSS 类,所以屏幕阅读器无法读取。
|
||||
<strong>注意:</strong><br>对于有标题的图片,我们依然需要添加<code>alt</code>属性,因为这样有助于搜索引擎记录图片内容。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 已经大体写好了博客页面。他打算使用忍者刀图片作为两篇文章之间的分割线,并为图片添加一个空的<code>alt</code>属性(注意:这里<code>img</code>标签的<code>src</code>属性提供的链接是无效的,因此页面上可能不会显示图片,不用担心)。
|
||||
</section>
|
||||
**注意:**
|
||||
对于有标题的图片,我们依然需要添加`alt`属性,因为这样有助于搜索引擎记录图片内容。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的<code>img</code>标签应该包含<code>alt</code>属性。'
|
||||
testString: assert(!($('img').attr('alt') == undefined));
|
||||
- text: '<code>alt</code>属性对应的值应该为空。'
|
||||
testString: assert($('img').attr('alt') == '');
|
||||
Camper Cat 已经大体写好了博客页面。他打算使用忍者刀图片作为两篇文章之间的分割线,并为图片添加一个空的`alt`属性(注意:这里`img`标签的`src`属性提供的链接是无效的,因此页面上可能不会显示图片,不用担心)。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的`img`标签应该包含`alt`属性。
|
||||
|
||||
```js
|
||||
assert(!($('img').attr('alt') == undefined));
|
||||
```
|
||||
|
||||
</section>
|
||||
`alt`属性对应的值应该为空。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
<article>
|
||||
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
|
||||
<p>To Come...</p>
|
||||
</article>
|
||||
|
||||
<img src="samuraiSwords.jpeg">
|
||||
|
||||
<article>
|
||||
<h2>Is Chuck Norris a Cat Person?</h2>
|
||||
<p>To Come...</p>
|
||||
</article>
|
||||
```js
|
||||
assert($('img').attr('alt') == '');
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,15 +1,17 @@
|
||||
---
|
||||
id: 587d778d367417b2b2512aaa
|
||||
title: 使用自定义 CSS 让元素仅对屏幕阅读器可见
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cJ8QGkhJ'
|
||||
forumTopicId: 301020
|
||||
title: 使用自定义 CSS 让元素仅对屏幕阅读器可见
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
# --description--
|
||||
|
||||
到目前为止,所有关于可访问性的挑战都没有使用 CSS。这是为了让你在关注外观样式之前,先把页面的逻辑结构写清,以及明确语义化标签的重要性。
|
||||
|
||||
然而,如果我们需要在页面中添加一些只对屏幕阅读器可见的内容时,CSS 可以提升页面的可访问性。当信息以可视化形式(如:图表)展示,而屏幕阅读器用户需要一种替代方式(如:表格)来获取信息时,就会出现这种情况。CSS 被用来将这些仅供屏幕阅读器使用的信息定位到浏览器可见区域之外。
|
||||
|
||||
举个例子:
|
||||
|
||||
```css
|
||||
@ -23,140 +25,43 @@ title: 使用自定义 CSS 让元素仅对屏幕阅读器可见
|
||||
}
|
||||
```
|
||||
|
||||
<strong>注意:</strong><br>下面的 CSS 代码与上面的结果不同:
|
||||
**注意:**
|
||||
下面的 CSS 代码与上面的结果不同:
|
||||
|
||||
<ul>
|
||||
<li><code>display: none;</code>或<code>visibility: hidden;</code>会把内容彻底隐藏起来,对于屏幕阅读器也不例外。</li>
|
||||
<li>如果把值设置为 0px,如<code>width: 0px; height: 0px;</code>,意味着让元素脱离文档流,这样做也会让元素被屏幕阅读器忽略。</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 为他的训练页面创建了一个十分酷炫的条形图,并将数据放入表格中,供屏幕阅读器用户使用。表格已经有了一个<code>sr-only</code>类,但是还没有添加 CSS 规则。请设置<code>position</code>的值为 absolute,<code>left</code> 的值为 -10000px,<code>width</code>与<code>height</code>的值为 1px。
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
Camper Cat 为他的训练页面创建了一个十分酷炫的条形图,并将数据放入表格中,供屏幕阅读器用户使用。表格已经有了一个`sr-only`类,但是还没有添加 CSS 规则。请设置`position`的值为 absolute,`left` 的值为 -10000px,`width`与`height`的值为 1px。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>sr-only</code>类中的<code>position</code>属性的值应为 absolute。'
|
||||
testString: assert($('.sr-only').css('position') == 'absolute');
|
||||
- text: '<code>sr-only</code>类中的<code>left</code>属性的值应为 -10000px。'
|
||||
testString: assert($('.sr-only').css('left') == '-10000px');
|
||||
- text: '<code>sr-only</code>类中的<code>width</code>属性的值应为 1px。'
|
||||
testString: assert(code.match(/width:\s*?1px/gi));
|
||||
- text: '<code>sr-only</code>类中的<code>height</code>属性的值应为 1px。'
|
||||
testString: assert(code.match(/height:\s*?1px/gi));
|
||||
# --hints--
|
||||
|
||||
`sr-only`类中的`position`属性的值应为 absolute。
|
||||
|
||||
```js
|
||||
assert($('.sr-only').css('position') == 'absolute');
|
||||
```
|
||||
|
||||
</section>
|
||||
`sr-only`类中的`left`属性的值应为 -10000px。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<head>
|
||||
<style>
|
||||
.sr-only {
|
||||
position: ;
|
||||
left: ;
|
||||
width: ;
|
||||
height: ;
|
||||
top: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Training</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="#stealth">Stealth & Agility</a></li>
|
||||
<li><a href="#combat">Combat</a></li>
|
||||
<li><a href="#weapons">Weapons</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<section>
|
||||
<h2>Master Camper Cat's Beginner Three Week Training Program</h2>
|
||||
<figure>
|
||||
<!-- Stacked bar chart of weekly training-->
|
||||
<p>[Stacked bar chart]</p>
|
||||
<br />
|
||||
<figcaption>Breakdown per week of time to spend training in stealth, combat, and weapons.</figcaption>
|
||||
</figure>
|
||||
<table class="sr-only">
|
||||
<caption>Hours of Weekly Training in Stealth, Combat, and Weapons</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th scope="col">Stealth & Agility</th>
|
||||
<th scope="col">Combat</th>
|
||||
<th scope="col">Weapons</th>
|
||||
<th scope="col">Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">Week One</th>
|
||||
<td>3</td>
|
||||
<td>5</td>
|
||||
<td>2</td>
|
||||
<td>10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Week Two</th>
|
||||
<td>4</td>
|
||||
<td>5</td>
|
||||
<td>3</td>
|
||||
<td>12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Week Three</th>
|
||||
<td>4</td>
|
||||
<td>6</td>
|
||||
<td>3</td>
|
||||
<td>13</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<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>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('.sr-only').css('left') == '-10000px');
|
||||
```
|
||||
|
||||
</div>
|
||||
`sr-only`类中的`width`属性的值应为 1px。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert(code.match(/width:\s*?1px/gi));
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
`sr-only`类中的`height`属性的值应为 1px。
|
||||
|
||||
```js
|
||||
assert(code.match(/height:\s*?1px/gi));
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,84 +1,50 @@
|
||||
---
|
||||
id: 587d7790367417b2b2512aaf
|
||||
title: 通过给元素添加 accesskey 属性来让用户可以在链接之间快速导航
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cQvmaTp'
|
||||
forumTopicId: 1
|
||||
title: 通过给元素添加 accesskey 属性来让用户可以在链接之间快速导航
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
HTML 提供<code>accesskey</code>属性,用于指定激活标签或者使标签获得焦点的快捷键,这可以使键盘用户的导航更加便捷。
|
||||
HTML5 允许在任何标签上使用这个属性。该属性 (如链接、按钮、表单控件等)十分有用。
|
||||
# --description--
|
||||
|
||||
HTML 提供`accesskey`属性,用于指定激活标签或者使标签获得焦点的快捷键,这可以使键盘用户的导航更加便捷。
|
||||
|
||||
HTML5 允许在任何标签上使用这个属性。该属性 (如链接、按钮、表单控件等)十分有用。
|
||||
|
||||
举个例子:
|
||||
<code><button accesskey="b">Important Button</button></code>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 希望为他的两篇博客的标题的链接设置快捷键,以使用户可以快速导航到文章的全文。请为这两个链接添加<code>accesskey</code>属性,并将第一个设置为 "g"(表示 Garfield),第二个设置为 "c"(表示 Chuck Norris)。
|
||||
</section>
|
||||
`<button accesskey="b">Important Button</button>`
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你应该为<code>id</code>是 "first" 的<code>a</code>标签添加<code>accesskey</code>属性。'
|
||||
testString: assert($('#first').attr('accesskey'));
|
||||
- text: '你应该为<code>id</code>是 "second" 的<code>a</code>标签添加<code>accesskey</code>属性。'
|
||||
testString: assert($('#second').attr('accesskey'));
|
||||
- text: '你应该将<code>id</code>是 "first" 的<code>a</code>标签的<code>accesskey</code>属性值设置为小写 "g"。'
|
||||
testString: assert($('#first').attr('accesskey') == 'g');
|
||||
- text: '你应该将<code>id</code>是 "second" 的<code>a</code>标签的<code>accesskey</code>属性值设置为小写 "c"。'
|
||||
testString: assert($('#second').attr('accesskey') == 'c');
|
||||
Camper Cat 希望为他的两篇博客的标题的链接设置快捷键,以使用户可以快速导航到文章的全文。请为这两个链接添加`accesskey`属性,并将第一个设置为 "g"(表示 Garfield),第二个设置为 "c"(表示 Chuck Norris)。
|
||||
|
||||
# --hints--
|
||||
|
||||
你应该为`id`是 "first" 的`a`标签添加`accesskey`属性。
|
||||
|
||||
```js
|
||||
assert($('#first').attr('accesskey'));
|
||||
```
|
||||
|
||||
</section>
|
||||
你应该为`id`是 "second" 的`a`标签添加`accesskey`属性。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<article>
|
||||
|
||||
|
||||
<h2><a id="first" href="">The Garfield Files: Lasagna as Training Fuel?</a></h2>
|
||||
|
||||
|
||||
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
|
||||
</article>
|
||||
<article>
|
||||
|
||||
|
||||
<h2><a id="second" href="">Is Chuck Norris a Cat Person?</a></h2>
|
||||
|
||||
|
||||
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
|
||||
</article>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('#second').attr('accesskey'));
|
||||
```
|
||||
|
||||
</div>
|
||||
你应该将`id`是 "first" 的`a`标签的`accesskey`属性值设置为小写 "g"。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('#first').attr('accesskey') == 'g');
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
你应该将`id`是 "second" 的`a`标签的`accesskey`属性值设置为小写 "c"。
|
||||
|
||||
```js
|
||||
assert($('#second').attr('accesskey') == 'c');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,91 +1,38 @@
|
||||
---
|
||||
id: 587d7788367417b2b2512aa3
|
||||
title: 使用 footer 元素使屏幕阅读器更容易导航
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/crVrDh8'
|
||||
forumTopicId: 301022
|
||||
title: 使用 footer 元素使屏幕阅读器更容易导航
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
与<code>header</code>和<code>nav</code>类似,<code>footer</code>也具有语义化特性,可以使辅助设备快速定位到它。它位于页面底部,用于呈现版权信息或者相关文档链接。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 的忍者训练页面进展顺利。请将他在页面底部呈现版权信息的<code>div</code>标签更改为<code>footer</code>标签。
|
||||
</section>
|
||||
与`header`和`nav`类似,`footer`也具有语义化特性,可以使辅助设备快速定位到它。它位于页面底部,用于呈现版权信息或者相关文档链接。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码中应该包含 1 个<code>footer</code>标签。'
|
||||
testString: assert($('footer').length == 1);
|
||||
- text: '你的代码中不应包含<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
- text: '你代码中的<code>footer</code>应该是闭合的。'
|
||||
testString: assert(code.match(/<footer>\s*© 2018 Camper Cat\s*<\/footer>/g));
|
||||
Camper Cat 的忍者训练页面进展顺利。请将他在页面底部呈现版权信息的`div`标签更改为`footer`标签。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码中应该包含 1 个`footer`标签。
|
||||
|
||||
```js
|
||||
assert($('footer').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的代码中不应包含`div`标签。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Training</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="#stealth">Stealth & Agility</a></li>
|
||||
<li><a href="#combat">Combat</a></li>
|
||||
<li><a href="#weapons">Weapons</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</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>
|
||||
|
||||
|
||||
<div>© 2018 Camper Cat</div>
|
||||
|
||||
|
||||
</body>
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
</div>
|
||||
你代码中的`footer`应该是闭合的。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert(code.match(/<footer>\s*© 2018 Camper Cat\s*<\/footer>/g));
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,86 +1,52 @@
|
||||
---
|
||||
id: 587d7787367417b2b2512aa1
|
||||
title: 使用 header 元素使屏幕阅读器更容易导航
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cB76vtv'
|
||||
forumTopicId: 301023
|
||||
title: 使用 header 元素使屏幕阅读器更容易导航
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<code>header</code>也是一个具有语义化的、提升页面可访问性的 HTML5 标签。它可以为父级标签呈现简介信息或者导航链接,适用于那些在多个页面顶部重复出现的内容。
|
||||
与<code>main</code>类似,<code>header</code>的语义化特性也可以使辅助技术快速定位到它的内容。
|
||||
<strong>注意:</strong><br><code>header</code>用在 HTML 文档的<code>body</code>标签中。这点与包含页面标题、元信息的<code>head</code>标签不同。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 正在写一些训练忍者的精彩文章,并为它们建立一个新的页面。请使用<code>header</code>替换页面顶端包含<code>h1</code>的<code>div</code>标签。
|
||||
</section>
|
||||
`header`也是一个具有语义化的、提升页面可访问性的 HTML5 标签。它可以为父级标签呈现简介信息或者导航链接,适用于那些在多个页面顶部重复出现的内容。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
与`main`类似,`header`的语义化特性也可以使辅助技术快速定位到它的内容。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该包含 1 个<code>header</code>标签。'
|
||||
testString: assert($('header').length == 1);
|
||||
- text: '你的<code>header</code>标签应该包含<code>h1</code>。'
|
||||
testString: assert($('header').children('h1').length == 1);
|
||||
- text: '你的代码不应有任何<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
- text: '确保你的<code>header</code>标签是闭合的。'
|
||||
testString: assert(code.match(/<\/header>/g) && code.match(/<\/header>/g).length === code.match(/<header>/g).length);
|
||||
**注意:**
|
||||
`header`用在 HTML 文档的`body`标签中。这点与包含页面标题、元信息的`head`标签不同。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 正在写一些训练忍者的精彩文章,并为它们建立一个新的页面。请使用`header`替换页面顶端包含`h1`的`div`标签。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码应该包含 1 个`header`标签。
|
||||
|
||||
```js
|
||||
assert($('header').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的`header`标签应该包含`h1`。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```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>
|
||||
```js
|
||||
assert($('header').children('h1').length == 1);
|
||||
```
|
||||
|
||||
</div>
|
||||
你的代码不应有任何`div`标签。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
确保你的`header`标签是闭合的。
|
||||
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/header>/g) &&
|
||||
code.match(/<\/header>/g).length === code.match(/<header>/g).length
|
||||
);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,91 +1,49 @@
|
||||
---
|
||||
id: 587d7788367417b2b2512aa2
|
||||
title: 使用 nav 元素使屏幕阅读器更容易导航
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/czVwWSv'
|
||||
forumTopicId: 301024
|
||||
title: 使用 nav 元素使屏幕阅读器更容易导航
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<code>nav</code>也是一个具有语义化特性的 HTML5 标签,用于呈现页面中的主导航链接。它可以使屏幕阅读器快速识别页面中的导航信息。
|
||||
对于在多个页面底部出现的站点链接,不需要使用<code>nav</code>,用<code>footer</code>(在下个挑战中介绍)会更好。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 在他的忍者训练页面顶端使用了很多导航链接,但把它们写在了<code>div</code>中。请将<code>div</code>更改为<code>nav</code>标签,以提升页面的可访问性。
|
||||
</section>
|
||||
`nav`也是一个具有语义化特性的 HTML5 标签,用于呈现页面中的主导航链接。它可以使屏幕阅读器快速识别页面中的导航信息。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
对于在多个页面底部出现的站点链接,不需要使用`nav`,用`footer`(在下个挑战中介绍)会更好。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该有 1 个<code>nav</code>标签。'
|
||||
testString: assert($('nav').length == 1);
|
||||
- text: '你的<code>nav</code>标签应该包含<code>ul</code>标签及其列表项。'
|
||||
testString: assert($('nav').children('ul').length == 1);
|
||||
- text: '你的代码不应包含<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
- text: '确保你的<code>nav</code>标签是闭合的。'
|
||||
testString: assert(code.match(/<\/nav>/g) && code.match(/<\/nav>/g).length === code.match(/<nav>/g).length);
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 在他的忍者训练页面顶端使用了很多导航链接,但把它们写在了`div`中。请将`div`更改为`nav`标签,以提升页面的可访问性。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码应该有 1 个`nav`标签。
|
||||
|
||||
```js
|
||||
assert($('nav').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的`nav`标签应该包含`ul`标签及其列表项。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Training with Camper Cat</h1>
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
<li><a href="#stealth">Stealth & Agility</a></li>
|
||||
<li><a href="#combat">Combat</a></li>
|
||||
<li><a href="#weapons">Weapons</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</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>
|
||||
```js
|
||||
assert($('nav').children('ul').length == 1);
|
||||
```
|
||||
|
||||
</div>
|
||||
你的代码不应包含`div`标签。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
确保你的`nav`标签是闭合的。
|
||||
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/nav>/g) &&
|
||||
code.match(/<\/nav>/g).length === code.match(/<nav>/g).length
|
||||
);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,102 +1,51 @@
|
||||
---
|
||||
id: 587d778c367417b2b2512aa9
|
||||
title: 使用 HTML5 的 datatime 属性标准化时间
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cmzMgtz'
|
||||
forumTopicId: 301025
|
||||
title: 使用 HTML5 的 datatime 属性标准化时间
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
继续日期主题。HTML5 还引入了<code>time</code>标签与<code>datetime</code>属性来标准化时间。<code>time</code>是一个行内标签,用于在页面中呈现日期或时间,而<code>datetime</code>属性保存了日期的有效格式,辅助设备可以访问这个值。通过标准化时间格式,即使时间在文本中是以非正式的或口语化的形式编写,辅助设备依然可以获取准确的时间和日期。
|
||||
# --description--
|
||||
|
||||
继续日期主题。HTML5 还引入了`time`标签与`datetime`属性来标准化时间。`time`是一个行内标签,用于在页面中呈现日期或时间,而`datetime`属性保存了日期的有效格式,辅助设备可以访问这个值。通过标准化时间格式,即使时间在文本中是以非正式的或口语化的形式编写,辅助设备依然可以获取准确的时间和日期。
|
||||
|
||||
举个例子:
|
||||
<code><p>Master Camper Cat officiated the cage match between Goro and Scorpion <time datetime="2013-02-13">last Wednesday</time>, which ended in a draw.</p></code>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 的比武大会的时间确定了!请使用<code>time</code>标签包含文本 "Thursday, September 15<sup>th</sup>",并将<code>datetime</code>属性设置为 "2016-09-15"。
|
||||
</section>
|
||||
`<p>Master Camper Cat officiated the cage match between Goro and Scorpion <time datetime="2013-02-13">last Wednesday</time>, which ended in a draw.</p>`
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --instructions--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>time</code>标签应该包含文本"Thursday, September 15<sup>th</sup>"。'
|
||||
testString: assert(timeElement.length);
|
||||
- text: '<code>time</code>标签应该有 1 个非空的<code>datetime</code>属性。'
|
||||
testString: assert(timeElement.length && $(timeElement).html().trim() === "Thursday, September 15<sup>th</sup>");
|
||||
- text: '<code>datetime</code>属性的值应该为 2016-09-15。'
|
||||
testString: assert(datetimeAttr && datetimeAttr.length);
|
||||
- text: '确保<code>time</code>标签是闭合的。'
|
||||
testString: assert(datetimeAttr === "2016-09-15");
|
||||
Camper Cat 的比武大会的时间确定了!请使用`time`标签包含文本 "Thursday, September 15<sup>th</sup>",并将`datetime`属性设置为 "2016-09-15"。
|
||||
|
||||
# --hints--
|
||||
|
||||
`time`标签应该包含文本"Thursday, September 15<sup>th</sup>"。
|
||||
|
||||
```js
|
||||
assert(timeElement.length);
|
||||
```
|
||||
|
||||
</section>
|
||||
`time`标签应该有 1 个非空的`datetime`属性。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Tournaments</h1>
|
||||
</header>
|
||||
<article>
|
||||
<h2>Mortal Kombat Tournament Survey Results</h2>
|
||||
|
||||
<!-- Add your code below this line -->
|
||||
|
||||
<p>Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is Thursday, September 15<sup>th</sup>. May the best ninja win!</p>
|
||||
|
||||
<!-- Add your code above this line -->
|
||||
|
||||
<section>
|
||||
<h3>Comments:</h3>
|
||||
<article>
|
||||
<p>Posted by: Sub-Zero on <time datetime="2016-08-13T20:01Z">August 13<sup>th</sup></time></p>
|
||||
<p>Johnny Cage better be there, I'll finish him!</p>
|
||||
</article>
|
||||
<article>
|
||||
<p>Posted by: Doge on <time datetime="2016-08-15T08:12Z">August 15<sup>th</sup></time></p>
|
||||
<p>Wow, much combat, so mortal.</p>
|
||||
</article>
|
||||
<article>
|
||||
<p>Posted by: The Grim Reaper on <time datetime="2016-08-16T00:00Z">August 16<sup>th</sup></time></p>
|
||||
<p>Looks like I'll be busy that day.</p>
|
||||
</article>
|
||||
</section>
|
||||
</article>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert(
|
||||
timeElement.length &&
|
||||
$(timeElement).html().trim() === 'Thursday, September 15<sup>th</sup>'
|
||||
);
|
||||
```
|
||||
|
||||
</div>
|
||||
`datetime`属性的值应该为 2016-09-15。
|
||||
|
||||
<div id='html-teardown'>
|
||||
|
||||
```html
|
||||
<script>
|
||||
const pElement = $("article > p")
|
||||
.filter((_, elem) => $(elem).text().includes("Thank you to everyone for responding to Master Camper Cat's survey."));
|
||||
const timeElement = pElement[0] ? $(pElement[0]).find("time") : null;
|
||||
const datetimeAttr = $(timeElement).attr("datetime");
|
||||
</script>
|
||||
```js
|
||||
assert(datetimeAttr && datetimeAttr.length);
|
||||
```
|
||||
|
||||
</div>
|
||||
确保`time`标签是闭合的。
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert(datetimeAttr === '2016-09-15');
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,77 +1,54 @@
|
||||
---
|
||||
id: 587d774d367417b2b2512a9e
|
||||
title: 使用标题显示内容的层次关系
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cqVEktm'
|
||||
forumTopicId: 301026
|
||||
title: 使用标题显示内容的层次关系
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
标题标签(包括<code>h1</code>到<code>h6</code>)有很高的使用率,它们用于描述内容的主题。在屏幕阅读器中,用户为更快地了解页面内容,可以设置让阅读器只朗读页面标题。这意味着标题标签之间以及标签本身都应语义化,不应仅仅为了获得不同字号而使用不同级别的标题标签。
|
||||
<em>语义化</em>:标签名能准确地表达它所含内容的信息类型。
|
||||
# --description--
|
||||
|
||||
标题标签(包括`h1`到`h6`)有很高的使用率,它们用于描述内容的主题。在屏幕阅读器中,用户为更快地了解页面内容,可以设置让阅读器只朗读页面标题。这意味着标题标签之间以及标签本身都应语义化,不应仅仅为了获得不同字号而使用不同级别的标题标签。
|
||||
|
||||
*语义化*:标签名能准确地表达它所含内容的信息类型。
|
||||
|
||||
对于一篇含有引言、正文、结论的论文,把结论作为引言的一部分没有任何意义,因为结论应该是独立的章节。类似地,页面中的标题标签也应该是有序的,并且能表明内容的层次关系。
|
||||
|
||||
在使用中,相同级别(或者更高级别)的标题标签用于开启新的章节,低一级别的标题标签用于开启上一级标题标签的子小节。
|
||||
举个例子:一个<code>h2</code>标签后紧跟若干<code>h4</code>标签的页面,会让使用屏幕阅读器的用户感到困惑。尽管在页面中,使用这 6 个标题标签可以控制内容的的视觉样式,但我们应该使用 CSS 来调整。
|
||||
最后一点,每个页面应该只有一个<code>h1</code>标签,用来说明页面主要内容。<code>h1</code>标签和其他的标题标签可以让搜索引擎获取页面的大纲。
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 希望他的网站有一个介绍如何成为忍者的页面。请帮助他修改标题标签,使它们语义化且顺序正确。你需要将所有的<code>h5</code>标题标签调整为恰当的级别(即<code>h3</code>标题标签),使它们是<code>h2</code>标题标签的子级。
|
||||
</section>
|
||||
举个例子:一个`h2`标签后紧跟若干`h4`标签的页面,会让使用屏幕阅读器的用户感到困惑。尽管在页面中,使用这 6 个标题标签可以控制内容的的视觉样式,但我们应该使用 CSS 来调整。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
最后一点,每个页面应该只有一个`h1`标签,用来说明页面主要内容。`h1`标签和其他的标题标签可以让搜索引擎获取页面的大纲。
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该包含 6 个<code>h3</code>标签。'
|
||||
testString: assert($("h3").length === 6);
|
||||
- text: '你的代码不应包含 <code>h5</code> 标签。'
|
||||
testString: assert((code.match(/\/h3/g) || []).length===6);
|
||||
- text: '代码不应该包含 <code>h5</code> 标记.'
|
||||
testString: assert($("h5").length === 0);
|
||||
- text: '代码不应该包含 <code>h5</code> 结束标记。'
|
||||
testString: assert(/\/h5/.test(code)===false);
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 希望他的网站有一个介绍如何成为忍者的页面。请帮助他修改标题标签,使它们语义化且顺序正确。你需要将所有的`h5`标题标签调整为恰当的级别(即`h3`标题标签),使它们是`h2`标题标签的子级。
|
||||
|
||||
# --hints--
|
||||
|
||||
你的代码应该包含 6 个`h3`标签。
|
||||
|
||||
```js
|
||||
assert($('h3').length === 6);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的代码不应包含 `h5` 标签。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<h1>How to Become a Ninja</h1>
|
||||
<main>
|
||||
<h2>Learn the Art of Moving Stealthily</h2>
|
||||
<h5>How to Hide in Plain Sight</h5>
|
||||
<h5>How to Climb a Wall</h5>
|
||||
|
||||
<h2>Learn the Art of Battle</h2>
|
||||
<h5>How to Strengthen your Body</h5>
|
||||
<h5>How to Fight like a Ninja</h5>
|
||||
|
||||
<h2>Learn the Art of Living with Honor</h2>
|
||||
<h5>How to Breathe Properly</h5>
|
||||
<h5>How to Simplify your Life</h5>
|
||||
</main>
|
||||
```js
|
||||
assert((code.match(/\/h3/g) || []).length === 6);
|
||||
```
|
||||
|
||||
</div>
|
||||
代码不应该包含 `h5` 标记.
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('h5').length === 0);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
代码不应该包含 `h5` 结束标记。
|
||||
|
||||
```js
|
||||
assert(/\/h5/.test(code) === false);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,105 +1,39 @@
|
||||
---
|
||||
id: 587d7790367417b2b2512ab0
|
||||
title: 使用 tabindex 将键盘焦点添加到元素中
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cmzMDHW'
|
||||
forumTopicId: 301027
|
||||
title: 使用 tabindex 将键盘焦点添加到元素中
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
HTML 的<code>tabindex</code>属性有三个不同与标签焦点的功能。当它在标签上时,表示标签可以获得焦点。它的值可以是零、负整数及正整数,并决定了标签的行为。
|
||||
当用户在页面中使用 tab 键时,有些标签,如:链接、表单控件,可以自动获得焦点。它们获得焦点的顺序与它们出现在文档流中的顺序一致。我们可以通过将<code>tabindex</code>属性值设为 0,来给其他标签赋予相同的功能,如:<code>div</code>、<code>span</code>、<code>p</code>等。举个例子:
|
||||
<code><div tabindex="0">I need keyboard focus!</div></code>
|
||||
<strong>注意:</strong><br><code>tabindex</code>属性值为负整数(通常为 -1)的标签也是有焦点的,只是不可以通过 tab 键来获得焦点。这种方法通常用于以编程的方式使内容获得焦点(如:激活用于弹出框的<code>div</code>标签),但是它超出了当前挑战的范围。
|
||||
</section>
|
||||
# --description--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 新建了一个调查,用来收集他的用户的信息。他知道输入框可以自动获得键盘焦点,但他希望确保当键盘用户切换标签时,焦点可以停留在指示文字上。请给<code>p</code>标签添加<code>tabindex</code>属性,并将它的值设置为 0。注意:使用<code>tabindex</code>属性可以使 CSS 伪类<code>:focus</code>在<code>p</code>标签上生效。
|
||||
</section>
|
||||
HTML 的`tabindex`属性有三个不同与标签焦点的功能。当它在标签上时,表示标签可以获得焦点。它的值可以是零、负整数及正整数,并决定了标签的行为。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
当用户在页面中使用 tab 键时,有些标签,如:链接、表单控件,可以自动获得焦点。它们获得焦点的顺序与它们出现在文档流中的顺序一致。我们可以通过将`tabindex`属性值设为 0,来给其他标签赋予相同的功能,如:`div`、`span`、`p`等。举个例子:
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你应该为表单中的<code>p</code>标签添加<code>tabindex</code>属性。'
|
||||
testString: assert($('p').attr('tabindex'));
|
||||
- text: '你应该将<code>p</code>标签的<code>tabindex</code>属性值设置为 0。'
|
||||
testString: assert($('p').attr('tabindex') == '0');
|
||||
`<div tabindex="0">I need keyboard focus!</div>`
|
||||
|
||||
**注意:**
|
||||
`tabindex`属性值为负整数(通常为 -1)的标签也是有焦点的,只是不可以通过 tab 键来获得焦点。这种方法通常用于以编程的方式使内容获得焦点(如:激活用于弹出框的`div`标签),但是它超出了当前挑战的范围。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 新建了一个调查,用来收集他的用户的信息。他知道输入框可以自动获得键盘焦点,但他希望确保当键盘用户切换标签时,焦点可以停留在指示文字上。请给`p`标签添加`tabindex`属性,并将它的值设置为 0。注意:使用`tabindex`属性可以使 CSS 伪类`:focus`在`p`标签上生效。
|
||||
|
||||
# --hints--
|
||||
|
||||
你应该为表单中的`p`标签添加`tabindex`属性。
|
||||
|
||||
```js
|
||||
assert($('p').attr('tabindex'));
|
||||
```
|
||||
|
||||
</section>
|
||||
你应该将`p`标签的`tabindex`属性值设置为 0。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<head>
|
||||
<style>
|
||||
p:focus {
|
||||
background-color: yellow;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Ninja Survey</h1>
|
||||
</header>
|
||||
<section>
|
||||
<form>
|
||||
|
||||
|
||||
<p>Instructions: Fill in ALL your information then click <b>Submit</b></p>
|
||||
|
||||
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username"><br>
|
||||
<fieldset>
|
||||
<legend>What level ninja are you?</legend>
|
||||
<input id="newbie" type="radio" name="levels" value="newbie">
|
||||
<label for="newbie">Newbie Kitten</label><br>
|
||||
<input id="intermediate" type="radio" name="levels" value="intermediate">
|
||||
<label for="intermediate">Developing Student</label><br>
|
||||
<input id="master" type="radio" name="levels" value="master">
|
||||
<label for="master">9th Life Master</label>
|
||||
</fieldset>
|
||||
<br>
|
||||
<fieldset>
|
||||
<legend>Select your favorite weapons:</legend>
|
||||
<input id="stars" type="checkbox" name="weapons" value="stars">
|
||||
<label for="stars">Throwing Stars</label><br>
|
||||
<input id="nunchucks" type="checkbox" name="weapons" value="nunchucks">
|
||||
<label for="nunchucks">Nunchucks</label><br>
|
||||
<input id="sai" type="checkbox" name="weapons" value="sai">
|
||||
<label for="sai">Sai Set</label><br>
|
||||
<input id="sword" type="checkbox" name="weapons" value="sword">
|
||||
<label for="sword">Sword</label>
|
||||
</fieldset>
|
||||
<br>
|
||||
<input type="submit" name="submit" value="Submit">
|
||||
</form><br>
|
||||
</section>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('p').attr('tabindex') == '0');
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,95 +1,54 @@
|
||||
---
|
||||
id: 587d7790367417b2b2512ab1
|
||||
title: 使用 tabindex 指定多个元素的键盘焦点顺序
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cmzRRcb'
|
||||
forumTopicId: 301028
|
||||
title: 使用 tabindex 指定多个元素的键盘焦点顺序
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<code>tabindex</code>属性还可以指定标签的 tab 键顺序,将它的值设置为大于或等于 1 就可以实现这个功能。
|
||||
<code>tabindex</code>属性值为 1 的标签将首先获得键盘焦点,然后焦点将按照指定的<code>tabindex</code>的值(如:2,3 等)的顺序进行移动,直到回到默认的或<code>tabindex</code>值为 0 的标签上,如此循环。
|
||||
# --description--
|
||||
|
||||
`tabindex`属性还可以指定标签的 tab 键顺序,将它的值设置为大于或等于 1 就可以实现这个功能。
|
||||
|
||||
`tabindex`属性值为 1 的标签将首先获得键盘焦点,然后焦点将按照指定的`tabindex`的值(如:2,3 等)的顺序进行移动,直到回到默认的或`tabindex`值为 0 的标签上,如此循环。
|
||||
|
||||
需要注意的是,当按照这种方式设置 tab 键顺序时,将会覆盖默认的顺序(标签在文档流中出现的顺序)。这可能会令那些希望从页面顶部开始导航的用户感到困惑。这个技术在某些情况下可能是必要的,但是对可访问性而言,在应用时要十分小心。
|
||||
|
||||
举个例子:
|
||||
<code><div tabindex="1">I get keyboard focus, and I get it first!</div></code>
|
||||
<code><div tabindex="2">I get keyboard focus, and I get it second!</div></code>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 在他的励志名言页面中有一个搜索区域,他打算使用 CSS 将这个区域定位在页面的右上角。Camper Cat 希望他的搜索<code>input</code>与提交<code>input</code>表单控件是 tab 键顺序的前两项。请为搜索<code>input</code>添加<code>tabindex</code>属性,其值为 1。为提交<code>input</code>添加<code>tabindex</code>属性,其值为 2。
|
||||
</section>
|
||||
`<div tabindex="1">I get keyboard focus, and I get it first!</div>`
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
`<div tabindex="2">I get keyboard focus, and I get it second!</div>`
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你应该为搜索<code>input</code>标签添加<code>tabindex</code>属性。'
|
||||
testString: assert($('#search').attr('tabindex'));
|
||||
- text: '你应该为提交<code>input</code>标签添加<code>tabindex</code>属性。'
|
||||
testString: assert($('#submit').attr('tabindex'));
|
||||
- text: '搜索<code>input</code>标签的<code>tabindex</code>属性值应该为 1。'
|
||||
testString: assert($('#search').attr('tabindex') == '1');
|
||||
- text: '提交<code>input</code>标签的<code>tabindex</code>属性值应该为 2。'
|
||||
testString: assert($('#submit').attr('tabindex') == '2');
|
||||
# --instructions--
|
||||
|
||||
Camper Cat 在他的励志名言页面中有一个搜索区域,他打算使用 CSS 将这个区域定位在页面的右上角。Camper Cat 希望他的搜索`input`与提交`input`表单控件是 tab 键顺序的前两项。请为搜索`input`添加`tabindex`属性,其值为 1。为提交`input`添加`tabindex`属性,其值为 2。
|
||||
|
||||
# --hints--
|
||||
|
||||
你应该为搜索`input`标签添加`tabindex`属性。
|
||||
|
||||
```js
|
||||
assert($('#search').attr('tabindex'));
|
||||
```
|
||||
|
||||
</section>
|
||||
你应该为提交`input`标签添加`tabindex`属性。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Even Deeper Thoughts with Master Camper Cat</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="">Home</a></li>
|
||||
<li><a href="">Blog</a></li>
|
||||
<li><a href="">Training</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<form>
|
||||
<label for="search">Search:</label>
|
||||
|
||||
|
||||
<input type="search" name="search" id="search">
|
||||
<input type="submit" name="submit" value="Submit" id="submit">
|
||||
|
||||
|
||||
</form>
|
||||
<h2>Inspirational Quotes</h2>
|
||||
<blockquote>
|
||||
<p>“There's no Theory of Evolution, just a list of creatures I've allowed to live.”<br>
|
||||
- Chuck Norris</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p>“Wise men say forgiveness is divine, but never pay full price for late pizza.”<br>
|
||||
- TMNT</p>
|
||||
</blockquote>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert($('#submit').attr('tabindex'));
|
||||
```
|
||||
|
||||
</div>
|
||||
搜索`input`标签的`tabindex`属性值应该为 1。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('#search').attr('tabindex') == '1');
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
提交`input`标签的`tabindex`属性值应该为 2。
|
||||
|
||||
```js
|
||||
assert($('#submit').attr('tabindex') == '2');
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
@ -1,17 +1,21 @@
|
||||
---
|
||||
id: 587d774e367417b2b2512aa0
|
||||
title: 使用 article 元素包裹文章内容
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cPp79S3'
|
||||
forumTopicId: 301029
|
||||
title: 使用 article 元素包裹文章内容
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<code>article</code>是另一个具有语义化特性的 HTML5 新标签。<code>article</code>是一个分段标签,用于呈现独立及完整的内容。这个标签适用于博客入口、论坛帖子或者新闻文章。
|
||||
# --description--
|
||||
|
||||
`article`是另一个具有语义化特性的 HTML5 新标签。`article`是一个分段标签,用于呈现独立及完整的内容。这个标签适用于博客入口、论坛帖子或者新闻文章。
|
||||
|
||||
有些技巧可以用来判断内容是否独立,像是如果内容脱离了上下文,是否仍然有意义?类似地,对于 RSS 提要中的文本,它是否有意义?
|
||||
|
||||
请牢记,使用辅助设备的用户依赖组织良好的、语义化的标签来获取页面中的信息。
|
||||
<strong>请注意<code>section</code>和<code>div</code>的区别:</strong><br><code>section</code>也是一个 HTML5 新标签,与<code>article</code>标签的语义含义略有不同。<code>article</code>用于独立的、完整的内容,而<code>section</code>用于对与主题相关的内容进行分组。它们可以根据需要嵌套着使用。举个例子:如果一本书是一个<code>article</code>的话,那么每个章节就是<code>section</code>。当内容组之间没有联系时,可以使用<code>div</code>。
|
||||
|
||||
**请注意`section`和`div`的区别:**
|
||||
`section`也是一个 HTML5 新标签,与`article`标签的语义含义略有不同。`article`用于独立的、完整的内容,而`section`用于对与主题相关的内容进行分组。它们可以根据需要嵌套着使用。举个例子:如果一本书是一个`article`的话,那么每个章节就是`section`。当内容组之间没有联系时,可以使用`div`。
|
||||
|
||||
```html
|
||||
<div> - groups content
|
||||
@ -19,68 +23,23 @@ title: 使用 article 元素包裹文章内容
|
||||
<article> - groups independent, self-contained content
|
||||
```
|
||||
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Camper Cat 打算使用<code>article</code>标签来呈现他的博客页面里的帖子,但是他忘记在顶部的帖子上使用它。请使用<code>article</code>标签来代替<code>div</code>标签。
|
||||
</section>
|
||||
Camper Cat 打算使用`article`标签来呈现他的博客页面里的帖子,但是他忘记在顶部的帖子上使用它。请使用`article`标签来代替`div`标签。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码中应该有 3 个<code>article</code>标签。'
|
||||
testString: assert($('article').length == 3);
|
||||
- text: '你的代码不应包含<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
你的代码中应该有 3 个`article`标签。
|
||||
|
||||
```js
|
||||
assert($('article').length == 3);
|
||||
```
|
||||
|
||||
</section>
|
||||
你的代码不应包含`div`标签。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
<main>
|
||||
<div>
|
||||
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
|
||||
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
|
||||
</div>
|
||||
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
|
||||
<article>
|
||||
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
|
||||
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
|
||||
</article>
|
||||
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
|
||||
<article>
|
||||
<h2>Is Chuck Norris a Cat Person?</h2>
|
||||
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
|
||||
</article>
|
||||
</main>
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
</div>
|
||||
# --solutions--
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -1,16 +1,19 @@
|
||||
---
|
||||
id: 587d778b367417b2b2512aa7
|
||||
title: 将单选按钮包裹在 fieldset 元素中以获得更好的可访问性
|
||||
challengeType: 0
|
||||
videoUrl: 'https://scrimba.com/c/cVJVefw'
|
||||
forumTopicId: 301030
|
||||
title: 将单选按钮包裹在 fieldset 元素中以获得更好的可访问性
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
下一个表单主题与单选按钮的可访问性有关。在上一个挑战中,单选按钮含有一个拥有<code>for</code>属性的<code>label</code>标签,<code>for</code>属性指向相关选项的<code>id</code>。然而单选按钮通常成组出现,用户必须其中选择一项。本次挑战介绍一种可以语义化呈现单选按钮组的方法。
|
||||
使用<code>fieldset</code>标签将单选按钮组包含在里面就可以实现这个目的,通常还会使用<code>legend</code>标签来为单选按钮组提供文字说明。屏幕阅读器也可以朗读这些文字。
|
||||
当选项的含义很明确时,如:性别选择,<code>fieldset</code>标签与<code>legend</code>标签就可以省略。这时,使用含有<code>for</code>属性的<code>label</code>标签就足够了。
|
||||
# --description--
|
||||
|
||||
下一个表单主题与单选按钮的可访问性有关。在上一个挑战中,单选按钮含有一个拥有`for`属性的`label`标签,`for`属性指向相关选项的`id`。然而单选按钮通常成组出现,用户必须其中选择一项。本次挑战介绍一种可以语义化呈现单选按钮组的方法。
|
||||
|
||||
使用`fieldset`标签将单选按钮组包含在里面就可以实现这个目的,通常还会使用`legend`标签来为单选按钮组提供文字说明。屏幕阅读器也可以朗读这些文字。
|
||||
|
||||
当选项的含义很明确时,如:性别选择,`fieldset`标签与`legend`标签就可以省略。这时,使用含有`for`属性的`label`标签就足够了。
|
||||
|
||||
举个例子:
|
||||
|
||||
```html
|
||||
@ -27,96 +30,44 @@ title: 将单选按钮包裹在 fieldset 元素中以获得更好的可访问性
|
||||
</form>
|
||||
```
|
||||
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
当用户使用邮件注册时,Camper Cat 想知道他们的忍者等级。通过上一个挑战的学习,Camper Cat 创建了一组单选按钮,并为每个选项的<code>label</code>标签添加了<code>for</code>属性,但是 Camper Cat 的代码依然需要你的帮助。请将包含单选按钮组的<code>div</code>标签替换为<code>fieldset</code>标签;将<code>p</code>标签替换为<code>legend</code>标签。
|
||||
</section>
|
||||
当用户使用邮件注册时,Camper Cat 想知道他们的忍者等级。通过上一个挑战的学习,Camper Cat 创建了一组单选按钮,并为每个选项的`label`标签添加了`for`属性,但是 Camper Cat 的代码依然需要你的帮助。请将包含单选按钮组的`div`标签替换为`fieldset`标签;将`p`标签替换为`legend`标签。
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
# --hints--
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '你的代码应该使用 1 个<code>fieldset</code>标签包含单选按钮组。'
|
||||
testString: assert($('fieldset').length == 1);
|
||||
- text: '确保<code>fieldset</code>标签是闭合的。'
|
||||
testString: assert(code.match(/<\/fieldset>/g) && code.match(/<\/fieldset>/g).length === code.match(/<fieldset>/g).length);
|
||||
- text: '你的代码应该有 1 个包含询问用户忍者等级文字的<code>legend</code>标签。'
|
||||
testString: assert($('legend').length == 1);
|
||||
- text: '你的代码不应该含有<code>div</code>标签。'
|
||||
testString: assert($('div').length == 0);
|
||||
- text: '你的代码不应该有包含询问用户忍者等级文字的<code>p</code>标签。'
|
||||
testString: assert($('p').length == 4);
|
||||
你的代码应该使用 1 个`fieldset`标签包含单选按钮组。
|
||||
|
||||
```js
|
||||
assert($('fieldset').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
确保`fieldset`标签是闭合的。
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='html-seed'>
|
||||
|
||||
```html
|
||||
<body>
|
||||
<header>
|
||||
<h1>Deep Thoughts with Master Camper Cat</h1>
|
||||
</header>
|
||||
<section>
|
||||
<form>
|
||||
<p>Sign up to receive Camper Cat's blog posts by email here!</p>
|
||||
<label for="email">Email:</label>
|
||||
<input type="text" id="email" name="email">
|
||||
|
||||
|
||||
<!-- Add your code below this line -->
|
||||
<div>
|
||||
<p>What level ninja are you?</p>
|
||||
<input id="newbie" type="radio" name="levels" value="newbie">
|
||||
<label for="newbie">Newbie Kitten</label><br>
|
||||
<input id="intermediate" type="radio" name="levels" value="intermediate">
|
||||
<label for="intermediate">Developing Student</label><br>
|
||||
<input id="master" type="radio" name="levels" value="master">
|
||||
<label for="master">Master</label>
|
||||
</div>
|
||||
<!-- Add your code above this line -->
|
||||
|
||||
|
||||
<input type="submit" name="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
<article>
|
||||
<h2>The Garfield Files: Lasagna as Training Fuel?</h2>
|
||||
<p>The internet is littered with varying opinions on nutritional paradigms, from catnip paleo to hairball cleanses. But let's turn our attention to an often overlooked fitness fuel, and examine the protein-carb-NOM trifecta that is lasagna...</p>
|
||||
</article>
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
<article>
|
||||
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
|
||||
<p>Felines the world over have been waging war on the most persistent of foes. This red nemesis combines both cunning stealth and lightning speed. But chin up, fellow fighters, our time for victory may soon be near...</p>
|
||||
</article>
|
||||
<img src="samuraiSwords.jpeg" alt="">
|
||||
<article>
|
||||
<h2>Is Chuck Norris a Cat Person?</h2>
|
||||
<p>Chuck Norris is widely regarded as the premier martial artist on the planet, and it's a complete coincidence anyone who disagrees with this fact mysteriously disappears soon after. But the real question is, is he a cat person?...</p>
|
||||
</article>
|
||||
<footer>© 2018 Camper Cat</footer>
|
||||
</body>
|
||||
```js
|
||||
assert(
|
||||
code.match(/<\/fieldset>/g) &&
|
||||
code.match(/<\/fieldset>/g).length === code.match(/<fieldset>/g).length
|
||||
);
|
||||
```
|
||||
|
||||
</div>
|
||||
你的代码应该有 1 个包含询问用户忍者等级文字的`legend`标签。
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```html
|
||||
// solution required
|
||||
```js
|
||||
assert($('legend').length == 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
你的代码不应该含有`div`标签。
|
||||
|
||||
```js
|
||||
assert($('div').length == 0);
|
||||
```
|
||||
|
||||
你的代码不应该有包含询问用户忍者等级文字的`p`标签。
|
||||
|
||||
```js
|
||||
assert($('p').length == 4);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
Reference in New Issue
Block a user