简体   繁体   English

将SVG内联或作为映像在可访问性上有什么区别?

[英]What's the difference in accessibility between having SVG inline or as an image?

I am developing a web page trying to focus on accessibility, and created different graphics in SVG to go in it. 我正在开发一个试图着重于可访问性的网页,并在SVG中创建了不同的图形。 After reading different sites online ( 1 , 2 , and 3 ), I included the <title> and <desc> tags, and added the attributes role and aria-labelledby to make the SVGs more accessible. 在线阅读不同网站后( 12 ,和3 ),我包括<title><desc>标签,并添加属性rolearia-labelledby使SVGs更容易获得。

Some of those sources, seem to claim (directly or indirectly) that using SVG inline is better for accessibility; 其中一些消息来源似乎(直接或间接地)声称内联使用SVG更好地实现了可访问性。 so I ran a few tests with NVDA to see the differences, but I fail to see any at first sight. 因此我对NVDA进行了一些测试,以了解差异,但是我一眼看不到任何差异。

For example, using a simple SVG: 例如,使用简单的SVG:

 <svg width="100" height="100" viewBox="0 0 100 100" role="img" aria-labelledby="title desc"> <title id="title">Abstract Forms</title> <desc id="desc">Red square containing a white circle containing a blue triangle pointing up.</desc> <g stroke="none" stroke-width="0"> <rect x="0" y="0" width="100" height="100" fill="red" /> <circle cx="50" cy="50" r="40" fill="white" /> <path d="M 50,20 80,70 20,70 Z" fill="blue" /> </g> </svg> 

If I add it to the page like that, NVDA reads " Graphic. Abstract Forms. Red square containing a white circle containing a blue triangle pointing up. " 如果我将其添加到页面中,则NVDA会读取“ 图形。抽象形式。红色正方形包含白色圆圈,蓝色正方形指向上方。

And if I save it into a myImg.svg file, and add it to the page like this: 如果我将其保存到myImg.svg文件中,并将其添加到页面中,如下所示:

<img src="myImg.svg" alt="Red square containing a white circle containing a blue triangle pointing up" title="Abstract Forms" />

NVDA then reads " Graphic. Red square containing a white circle containing a blue triangle pointing up. " (same thing as before, just not reading the title). NVDA然后读取“ 图形。红色正方形包含白色圆圈,白色圆圈包含朝上的蓝色三角形。 ”(与之前相同,只是不阅读标题)。

This may be an NVDA thing, and other screen readers may do it differently, but there doesn't seem to be any considerable difference between the two. 这可能是NVDA的事情,其他屏幕阅读器的做事方式可能有所不同,但是两者之间似乎没有太大的区别。 At least not to claim that inlining the SVG is better for accessibility. 至少不要声称内联SVG更好地实现了可访问性。

Then I thought it could be related to reading additional information; 然后,我认为这可能与阅读其他信息有关; for example, if there was some text within the graphic. 例如,如果图形中有一些文本。 So I added a <text x="50" y="50" fill="black">Hello World</text> at the end of the SVG... but NVDA read the same thing as before; 因此,我在SVG的末尾添加了<text x="50" y="50" fill="black">Hello World</text> ...但是NVDA读取的内容与以前相同; not even selecting the text it will read it (again I don't know if this is an NVDA thing and if other screen readers do it differently). 甚至不选择文本,它就会读取它(同样,我不知道这是否是NVDA内容,以及其他屏幕阅读器是否以其他方式进行了处理)。

So my questions are: what are the differences between having SVG inline or as an image? 所以我的问题是: 将SVG内联或作为映像有什么区别? And what are the benefits (for accessibility) of having the SVG inline? 内联SVG有什么好处(对于可访问性)?

You probably already self-answered your question. 您可能已经回答了自己的问题。

Inline-svg is interpreted as part of the html webpage. Inline-svg被解释为html网页的一部分。 So your svg title and description are interpreted as well and read by the screen reader. 因此,您的svg标题和说明也会被解释并由屏幕阅读器阅读。

When using an 'img' tag to include the svg, the file is handled like an external file (like a jpg) and so only the 'alt' attribute of the img tag (= the image description) is interpreted/read by the screen reader. 当使用'img'标签包含svg时,该文件的处理方式类似于外部文件(例如jpg),因此屏幕仅会解释/读取img标签的'alt'属性(=图片描述)读者。

I have currently no source and can't test it a the moment, but I think there are also differences for links within the svg code: Links within inline svg are read by the screenreader, links within external svg files not. 我目前没有任何资料,暂时无法测试,但是我认为svg代码中的链接也有差异:内嵌svg中的链接由屏幕阅读器读取,而外部svg文件中的链接则无法。

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

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