html - 将两个元素(icon 和<a>)作为一个元素的辅助功能

标签 html accessibility

我有一个链接,前面有一个图标。在提出可访问性投诉时,我们希望将其视为单个元素(图 1),而不是当前场景中的两个元素(图 2)。关于如何实现这一目标的任何线索?

<div class="col-cta" style="height: 19px; margin-bottom: 0px; margin-top: 0px;">
  <a href="#" class="content-link" title="Link">
    ::before
    Link
  </a>
</div>

图片 1: element should be selected by screen reader like this

图 2: screen reader should NOT select it as two elements

最佳答案

<div class="col-cta" style="height: 19px; margin-bottom: 0px; margin-top: 0px;">
  <a href="#" class="content-link" aria-label="Link to xx">
    <span role="presentation">&#8250;&#160;</span>Link
  </a>
</div>

解释

  • 使用 aria-label超链接上的属性并为其指定一个易于访问的名称。

  • <span>其中包含的图标已被赋予 role=presentation 当元素需要在 DOM 中,但它们的语义不准确或不必要时使用。

关于html - 将两个元素(icon 和<a>)作为一个元素的辅助功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51960570/

相关文章:

html - 向对话框添加标签会阻止 VoiceOver 访问 Safari 中的动态内容

iOS:画外音无法正确读取 ".03 hours"文本

c++ - 如何在 Qt 中为我们可以使用 Windows Narrator 阅读的任何 QLabel 设置可访问的名称

accessibility - 使用 WAVE 工具检查本地 html 文件

jquery - 屏幕阅读器可以是 DIV 元素中的 "locked"吗?

html - native HTML 是否具有 ListBox 元素

html - 减少两个 td 之间的空间

javascript - 将 onclick 更改图像附加到没有 id 标签的 varing img 数量

html - Jekyll 网站上未显示网站图标

html - 错误的图像悬停效果