freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/applied-accessibility/know-when-alt-text-should-b...

2.3 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d774c367417b2b2512a9d Know When Alt Text Should be Left Blank 0 知道Alt文本应该留空

Description

在上一个挑战中您了解到在img标记上包含alt属性是必需的。但是,有时图像与已经描述它们的标题分组,或仅用于装饰。在这些情况下, alt文本可能看似多余或不必要。在已经使用文本内容解释图像或者没有为页面添加含义的情况下, img仍然需要alt属性,但可以将其设置为空字符串。这是一个例子: <img src="visualDecoration.jpeg" alt="">背景图片通常也属于“装饰”标签。但是它们通常应用CSS规则因此不是标记屏幕阅读器进程的一部分。 注意
对于带有标题的图像,您可能仍希望包含alt文本,因为它有助于搜索引擎对图像内容进行编目。

Instructions

Camper Cat已为其网站的博客部分编写了一个骨架页面。他计划在他的两篇文章之间用武士刀的装饰图像添加一个视觉中断。将alt属性添加到img标记并将其设置为空字符串。 (请注意,图像src不会链接到实际文件 - 不要担心显示屏中没有显示剑。)

Tests

tests:
  - text: 你的<code>img</code>标签应该有一个<code>alt</code>属性。
    testString: 'assert(!($("img").attr("alt") == undefined), "Your <code>img</code> tag should have an <code>alt</code> attribute.");'
  - text: <code>alt</code>属性应设置为空字符串。
    testString: 'assert($("img").attr("alt") == "", "The <code>alt</code> attribute should be set to an empty string.");'

Challenge Seed

<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>

Solution

// solution required