【问题标题】:Semantically/accessibly correct use of <details> for an image caption?语义/可访问地正确使用 <details> 作为图像标题?
【发布时间】:2021-12-14 12:04:27
【问题描述】:

我有一些很长的图片标题,我想使用&lt;details&gt; 标签来容纳这些。但我不确定如何以与 figcaptionfigure 相同的方式将细节与图像进行语义/可访问地关联。

这样做的正确方法是什么?

<img src="https://placeimg.com/150/100/nature" alt="Epcot theme park" />
<details>
  <summary>Epcot theme park</summary>
  <p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p>
</details>

这里的替代文字和摘要标题是一样的。

【问题讨论】:

    标签: html accessibility semantic-markup


    【解决方案1】:

    您可以使用&lt;figure&gt;&lt;figcaption&gt; 元素以编程方式将&lt;details&gt; 元素的内容与&lt;img&gt; 元素相关联,如示例所示:

    <figure>
        <img src="https://placeimg.com/150/100/nature" alt="Alt text that's different from your summary">
        <figcaption>
            <details>
                <summary>Epcot theme park</summary>
                <p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p>
            </details>
        </figcaption>
    </figure>
    

    &lt;figcaption&gt; 元素接受 flow content,其中包括 &lt;details&gt; 元素。

    您可能也有兴趣查看W3C Web Accessibility Tutorials for Complex Images,因为那里有一些非常相关的信息。

    【讨论】:

    • 很好,但为什么 role="group" 不会破坏 &lt;figcaption&gt;?无论哪种方式+1,我只是不确定那部分?
    • 角色可能很方便,但在这种情况下,它会导致&lt;figure&gt; 元素被宣布为图形元素。 没有role,NVDA 会说,"figure graphics Alt text..."使用role,NVDA 将不再使用“figure”。一般来说,最好不要更改本机语义元素的语义 (w3.org/TR/aria-in-html/#second)。但这是一个很好的答案,否则。
    • @slugolicious -- 我自己对这个角色有点不确定,但这就是它在 W3C 示例中的呈现方式(参见我帖子中的链接)。我找不到它存在的任何不良后果,所以我离开了它。我还使用 NVDA 进行了测试。不管省略“图”这个词,NVDA 的回应都是可以理解的,而且是有道理的。
    • 这项技术在 ARIA 17 中作为 WCAG 2.2 的一部分进行了概述:w3.org/WAI/WCAG21/Techniques/aria/ARIA17.html
    • @Josh 这是用于表单控件的。在这种情况下它不相关。 role="group" 不应在此上下文中使用。
    猜你喜欢
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 2021-05-18
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    相关资源
    最近更新 更多