当一个地标元素有一个标题时,它应该有一个咏叹调标签吗?



屏幕阅读器用户有多个选项来访问页面上的内容。
例如所有标题的列表,但也包括地标列表。
使用aria-label,您可以标记地标。

考虑以下标记:

<main>
<h1>My Blog items</h1>

<article aria-label="Why blueberries tast good">
<h2>Why blueberries tast good</h2>
<p>Some content about blueberries</p>
<a href="/why-blueberries-test-good">Read more</a>
</article>

<article aria-label="I don't like apples">
<h2>I don't like apples</h2>
<p>Text about why I don't like apples</p>
<a href="/i-dont-like-apples">Read more</a>
</article>

<article aria-label="Oranges are orange">
<h2>Oranges are orange</h2>
<p>An article discussing the color of fruit</p>
<a href="/oranges-are-orange">Read more</a>
</article>
</main>

上面示例中的aria-label对屏幕阅读器用户有用吗,还是它们是多余的?

aria-label的行为是理解何时使用它的关键。

所以在评论中,我问这些是页面内嵌的帖子还是链接到其他页面的摘录。

这很重要的原因是aria-label的行为。

如果你将aria-label添加到容器中,它将覆盖该容器中的所有内容.

所以,如果这些只是完整的文章,aria-label将取代整个博客的内容。

示例1 -页面上的实际文章例如:

<article aria-label="Why blueberries taste good">
<h2>Why blueberries taste good</h2>
<p>Some content about blueberries which could be hundreds of paragraphs long</p>
</article>

只能被理解为"为什么蓝莓好吃";对于屏幕阅读器用户来说,所有的帖子内容都将丢失。(有点,显然活动元素,如链接等,仍然可以读取和访问,所以它不是直接的,但希望你能明白)。

因此在上面的例子中,aria-label应该被删除。

示例2 -整篇文章是一个链接

现在,如果这是一个包含摘录的帖子列表,那么我们可能不希望摘录文本作为超链接文本的一部分被读取。

例如: -

<article>
<a href="somewhere" aria-label="Why blueberries taste good">
<h2>Why blueberries taste good</h2>
<p>Some content about blueberries which could be hundreds of paragraphs long</p>
</a>
</article>

在上面的例子中,整篇文章的摘录是超链接文本的一部分,所以我们可能会决定最好重写它,只使用文章标题作为链接文本。

但是,请参阅"最终想法"。部分,因为我仍然认为有更好的方法来做到这一点

你的例子在你给的例子中,我根本不会使用aria-label

现在这部分取决于aria-label的行为,如前所述,但更重要的是取决于屏幕阅读器用户导航页面的方式。

屏幕阅读器有列出页面上所有链接的快捷方式,可以循环浏览标题和部分。这是屏幕阅读器用户的"定向"方式。浏览页面和页面内容。

你的例子做事情的方式是好的和容易理解的。屏幕阅读器用户可以通过章节(<article>)、标题(<h2>)或超链接进行导航。

添加aria-label实际上对屏幕阅读器用户来说更糟糕,因为他们可能会或可能不会(取决于屏幕阅读器和浏览器组合)能够访问<h2>s,因为您已经覆盖了它们。

示例3 -与您的相同,但删除了aria-label

<article>
<h2>Oranges are orange</h2>
<p>An article discussing the color of fruit</p>
<a href="/oranges-are-orange">Read more</a>
</article>

正确使用aria-label

aria-label用于在没有任何信息的地方添加信息(或者在某些情况下添加可视的上下文信息)。

例如,如果你有社交媒体图标作为你的社交媒体渠道的链接,那么添加aria-label是允许可访问性树向屏幕阅读器提供有意义的信息的一种方法。

尽量少用,把aria-label当作最后的手段在您用尽所有语义上合适的选项之后。

对上述例子的最后思考

我个人会使用aria-hidden而不是aria-label,例如2(我们有一个文章列表,整篇文章是一个链接)。

所以我将按照下面的方式来组织它们:

<article>
<a href="somewhere">
<h2>Why blueberries taste good</h2>
<!--using `aria-hidden` on the excerpt text so that the `<h2>` is more likely to be discoverable using headings shortcuts-->
<div aria-hidden="true">
<p>Some content about blueberries which could be hundreds of paragraphs long</p>
</div> 
</a>
</article>

这样做的原因是(如前所述)我们现在没有可能覆盖<h2>,所以在所有的屏幕阅读器中,用户现在应该能够通过标题和超链接发现这篇文章。

这不是小题大做——但你可以使用aria-labelledby来引用标题的ID,以避免文本重复。

相关内容

最新更新