简体   繁体   English

隐藏屏幕阅读器的纯装饰性链接(例如产品列表图像)

[英]Hiding purely decorative links for screen readers (such as product listing images)

Is it accessible to hide image links using tabindex="-1" aria-hidden="true" on the anchor tag if the image as alt="" , provides no real content value, and is purely decorative?如果图像为alt=""并没有提供真正的内容价值并且纯粹是装饰性的,是否可以在锚标签上使用tabindex="-1" aria-hidden="true"隐藏图像链接?

My example below is of a "product listing" style of content.我下面的示例是“产品列表”样式的内容。 This is really a follow-up question to What is best practice (and legal) for product listing image alt text for accessibility?这实际上是关于产品列表图像替代文本的最佳实践(和法律)以实现可访问性的后续问题? regarding best practices for product listings, but could be relevant in other scenarios.关于产品列表的最佳实践,但可能与其他场景相关。 While ideally you may just have one anchor tag wrapping both the image and product name elements, this might not be possible based on other content within the list block or if you don't have enough control of the actual markup to move this around depending on the project you are working on.虽然理想情况下,您可能只有一个锚标记来包装图像和产品名称元素,但这可能无法基于列表块中的其他内容,或者如果您没有足够的控制实际标记来移动它,具体取决于您正在从事的项目。

In these cases, I still need the image clickable for users, but don't want to force screen reader users to have to tab through redundant links and listen to duplicate/unnecessary content.在这些情况下,我仍然需要用户可点击的图像,但不想强迫屏幕阅读器用户必须通过冗余链接标签并收听重复/不必要的内容。 I've tested this on VoiceOver and NVDA and it appears to work well.我已经在 VoiceOver 和 NVDA 上对此进行了测试,它似乎运行良好。

Is this a valid method or are there drawbacks that would cause issues for some users?这是一种有效的方法还是存在会导致某些用户出现问题的缺点?

 .product-list { list-style-type: none; margin: 1rem 0; padding: 0; }.product-list li { display: inline-block; margin: 0; padding: 0; text-align: center; vertical-align: top; }.label, .name { display: block; }.sr-only:not(:focus):not(:active) { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
 <h1>Image Anchor Link with Tabindex -1</h1> <ul class="product-list"> <li> <a href="/#first-link.html" tabindex="-1" aria-hidden="true"> <img src="https://place-puppy.com/200x200" alt=""> </a> <span class="label"><span class="sr-only">Label: </span> Featured</span> <a class="name" href="/#first-link.html">Sparky</a> </li> <li> <a href="/#first-link.html" tabindex="-1" aria-hidden="true"> <img src="https://place-puppy.com/200x200" alt=""> </a> <span class="label"><span class="sr-only">Label: </span> New</span> <a class="name" href="/#first-link.html">Fletcher</a> </li> <li> <a href="/#first-link.html" tabindex="-1" aria-hidden="true"> <img src="https://place-puppy.com/200x200" alt=""> </a> <a class="name" href="/#first-link.html">Tallulah</a> </li> </ul>

This looks acceptable, but you must be careful.这看起来可以接受,但你必须小心。

Since the image link is totally unreachable with the keyboard (because of tabindex=-1) or for a screen reader user (because of aria-hidden=true), you must make sure that the text link that follows points to the same page, otherwise you will create pages that those users won't be able to reach at all.由于使用键盘(因为 tabindex=-1)或屏幕阅读器用户(因为 aria-hidden=true)完全无法访问图像链接,因此您必须确保后面的文本链接指向同一页面,否则,您将创建这些用户根本无法访问的页面。 But as long as this condition is satisfied, it looks fine.但只要满足这个条件,它看起来就很好。

However, note that it would probably be better, if you can, to put everything in the same link, like this:但是,请注意,如果可以的话,将所有内容放在同一个链接中可能会更好,如下所示:

<li>
<a href="productXYZ">
<img src=productXYZ.png" alt="" />
Product XYZ
</a>
</li>

IN this example, since the image has an empty alt but has another text, everything is fine, only the text of the link will be read.在这个例子中,由于图像有一个空的 alt 但有另一个文本,一切都很好,只会读取链接的文本。

The problem comes from image only links without alt text.问题来自没有替代文本的仅图像链接。 They are a problem because screen readers have to find some text to speak even though there is none.它们是一个问题,因为即使没有文本,屏幕阅读器也必须找到一些要说的文本。 Several screen readers take the file name in that case, which most of the time doesn't mean anything to the user.在这种情况下,有几个屏幕阅读器采用文件名,这在大多数情况下对用户没有任何意义。 You are working around the problem with your solution, but the best would be to not have this problem at all, isn't it?你正在用你的解决方案解决这个问题,但最好的办法是根本没有这个问题,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM