简体   繁体   English

如何最好地格式化缩略图以实现可访问性?

[英]How to best format thumbnails for accessibility?

I am frequently tasked with displaying a grid of thumbnails for work, such as on a posts/articles page, with each thumbnail linking to a separate post/article, but I have never really been sure of the best way to format these for screen readers/accessibility.我经常需要为工作显示一个缩略图网格,例如在帖子/文章页面上,每个缩略图链接到一个单独的帖子/文章,但我从来没有真正确定为屏幕阅读器格式化这些的最佳方式/可访问性。 More specifically, I have never been sure whether to use the <article> or <figure> tag for this purpose, or neither, or something else entirely.更具体地说,我一直不确定是否为此目的使用 <article> 或 <figure> 标签,或者两者都不使用,或者完全是其他东西。 Does anyone know?有人知道吗? These are the three methods I am debating between:这些是我正在争论的三种方法:

<a>
    <article>
        <img />
        <div></div>
    </article>
</a>

<a>
    <figure>
        <img />
        <figcaption></figcaption>
    </figure>
</a>

<a>
    <img />
    <div></div>
</a>

The documentation for the article tag says that it "represents a self-contained composition in a document, page, application, or site, which is intended to be independently distributable or reusable".文章标签的文档说它“代表文档、页面、应用程序或站点中的自包含组合,旨在独立分发或重用”。 I don't know what that means in this context, but it seems like it could be intended for this purpose, or it could be meant to be used once on the actual article pages and not the overall "articles" list page.我不知道在这种情况下这意味着什么,但它似乎可以用于此目的,或者它可能意味着在实际文章页面而不是整个“文章”列表页面上使用一次。

The documentation for the figure tag says that it "represents self-contained content, potentially with an optional caption". figure 标签的文档说它“代表独立的内容,可能带有可选的标题”。 It seems like it would work quite well here, except my intuition says that it might be intended more for figures that are inline with the text of articles, so I have my doubts.它似乎在这里工作得很好,除了我的直觉说它可能更多地用于与文章文本内联的图形,所以我有我的怀疑。

The 3rd option is to use neither the article or the figure tag in an effort to just simplify the html as much as possible so that screen readers do not have to look at and interpret as many nested tags.第三个选项是既不使用 article 也不使用 figure 标签,以尽可能简化 html,这样屏幕阅读器就不必查看和解释尽可能多的嵌套标签。

References:参考:

From an accessibility perspective, I have not found much benefit to using an <article> .从可访问性的角度来看,我没有发现使用<article>有什么好处。 On iOS and Mac, Safari incorrectly treats an <article> as a landmark even though the definition of an article role specifically says it isn't.在 iOS 和 Mac 上,Safari错误地<article>视为地标,即使article 角色的定义明确说明它不是。

An article is not a navigational landmark, but may be nested to form a discussion where assistive technologies could pay attention to article nesting to assist the user in following the discussion.文章不是导航地标,但可以嵌套形成讨论,其中辅助技术可以关注文章嵌套以帮助用户关注讨论。

Notice that it says AT could pay attention to the article element but other than the aforementioned treatment as a landmark in Safari, I have not found NVDA, JAWS, or Voiceover to do anything special with an <article> .请注意,它说 AT可以关注 article 元素,但除了前面提到的作为 Safari 中的地标的处理之外,我还没有发现 NVDA、JAWS 或 Voiceover 可以对<article>做任何特别的事情。

If you plan on having a caption below the image, then you could use <figcaption> .如果您计划在图片下方添加标题,则可以使用<figcaption> It's just a handy way to visually display text below an image.这只是一种在图像下方直观显示文本的简便方法。 But if the thumbnail doesn't have text below it but rather has a heading or link to the article, then <figcaption> isn't needed.但是,如果缩略图下方没有文本,而是有标题或指向文章的链接,则不需要<figcaption>

Your last example, the simplest, is the most common way to code what you want and works just fine for accessibility.你的最后一个例子,最简单的,是最常见的编码你想要的东西的方法,并且可以很好地实现可访问性。 I know your code snippets were just minimal code but make sure your <img> uses the alt attribute.我知道您的代码片段只是最少的代码,但请确保您的<img>使用alt属性。

If your image is inside your link (as in your example) and there's other text containing the title of the article within the link, then the image can have an empty alt="" (or even just alt with no value).如果您的图片位于您的链接内(如您的示例所示) ,并且链接内还有其他包含文章标题的文本,则该图片可以有一个空的alt="" (或者甚至只是没有价值的alt )。 But if there isn't any visible text in the link, then make sure the image has an appropriate alt attribute value.但是,如果链接中没有任何可见文本,请确保图像具有适当的alt属性值。

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

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