内联 SVG <标题><描述>可访问性的正确用法

2023-07-31前端开发问题
8

本文介绍了内联 SVG <标题><描述>可访问性的正确用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在我的 html 中使用了很多内联 svg,但对于在可访问性方面呈现它们的最佳方式有点困惑.

I am using a lot of inline svgs in my html and am a little confused about the best way to present them concerning accessibility.

我看到了两种将 <title><desc> 添加到 svgs 的方法 -

I've see two methods to add <title> and <desc> to svgs -

<svg role="img" aria-label="[title + description]">
 <title>title text here</title>
 <desc>a description of the image here</desc>
 <path> etc.
</svg>

<svg role="img" aria-labelledby="my_svg_title my_svg_description">
 <title id="my_svg_title">title text here</title>
 <desc id="my_svg_description">a description of the image here</desc>
 <path> etc.
</svg>

第一种方法似乎是最好的,因为我不必为每个标题和描述提供唯一的 ID(我每页有多个 svg)?是这样吗?选择aria-label"或aria-labelledby"时还有什么需要考虑的吗?

The first method seems the best as I don't have to give unique IDs to each title and description (I have multiple svgs per page)? Is that the case? Is there anything else to take into consideration when choosing "aria-label" or "aria-labelledby"?

另外,我对这个角色还有点困惑 <desc > 播放 - 它与 alt 完全相同吗?我总是从内联 svgs 中删除 xmlns 和 xmlns:xlink 标签以进行优化,谷歌图像搜索是否仍会将这些内联 svgs 引用为图像?<desc> 会帮忙吗?

Also I am still confused a little about the role < desc > plays - is it exactly the same as alt? I always remove the xmlns and xmlns:xlink tags from inline svgs for optimisation, will google image search still reference these inline svgs as images? Will <desc> help with that?

如果内联 svg 将始终显示(内联 svg 是否永远不会呈现?),那么 <desc> 将永远不会对丢失的图像有用,这只会让页面阅读器具有可访问性,这可能用它.是吗?

If the inline svg will always display (do inline svgs ever not render?) then the <desc> will never be useful for missing images, which then only leaves page readers for accessibility which could use it. Do they?

基本上值得使用/包含<desc>吗?

Basically is it worth using/including <desc>?

推荐答案

想想</code>就像<code>alt</code>,想想<code><description></code> 喜欢 <code><figcaption></code><em class="showen"></em></p> <p class="en">Think of <code><title></code> like <code>alt</code>, think of <code><description></code> like <code><figcaption></code></p> <p class="cn">您的 <code><title></code> 应充分描述图像,以便用户了解图像包含的内容.<em class="showen"></em></p> <p class="en">Your <code><title></code> should describe the image sufficiently to provide a user with an understanding of what the image contains.</p> <p class="cn">如果它是一个复杂的图像,或者图像在需要更多细节的文章中起着至关重要的作用,则使用 <code><description></code>.<em class="showen"></em></p> <p class="en">If it is a complex image, or the image plays a vital role in an article that necessitates more details then use <code><description></code>.</p> <p class="cn">Deque 对不同的方法做了很好的测试,发现你的第二个版本是最可靠的,其中 <code>title</code> 和 <code>description</code> 通过 <code>aria-labelledby</code> 和 ID 链接,<strong>所以使用它</strong>.<em class="showen"></em></p> <p class="en">Deque did a great test of different methods and found that your second version was the most reliable with a <code>title</code> and <code>description</code> linked via <code>aria-labelledby</code> and IDs, <strong>so use that</strong>.</p> <p class="cn">是的,谷歌仍然会将它们引用为没有 <code>xmlns</code> 内联提供的图像(前提是您将页面作为 mime 类型 <code>text/html</code> 提供,否则您将遇到渲染问题).对于外部图像,我会保留它,这是一个很小的优化,不值得.<em class="showen"></em></p> <p class="en">Yes google will still reference them as images without <code>xmlns</code> served inline (provided you serve your page as mime type <code>text/html</code> otherwise you will get rendering issues). For external images I would leave it in, it is such a minor optimisation it isn't worth it.</p> <p class="cn">据我所知,内嵌 SVG 在 Google 图像搜索中没有被编入索引(但它们的内容仍然有助于您在 Google 搜索算法中的 SEO,因此仍然值得拥有 <code><description></code>在适当的地方.)<em class="showen"></em></p> <p class="en">Inline SVGs do not get indexed as far as I am aware in Google Image Search (but their content still contributes to your SEO in Google Search Algorithms slightly so it is still worth having <code><description></code> where appropriate.)</p> <p class="cn">如果内联,SVG 将始终呈现(假设浏览器支持 SVG,这很有可能).<em class="showen"></em></p> <p class="en">SVGs will always render if inline (assuming the browser supports SVG which is very likely). </p> <p class="cn">是的,如果图像足够复杂以至于您无法用 <code><title></code> 在 20 个字或更少的字数内描述它,则包括 <code><desc></code>(一般规则).<em class="showen"></em></p> <p class="en">Yes include <code><desc></code> if the image is sufficiently complex that you can't describe it with <code><title></code> in 20 words or less (general rule).</p> <p class="cn"><strong>最后的想法</strong> - <code>alt</code> 标签、<code>titles</code> 等都是关于可访问性的,不要担心它们的 SEO 关键字,因为你会最终损害可用性.我知道你没有提到,但为了清楚起见,我想我会把它放在这里.<em class="showen"></em></p> <p class="en"><strong>final thought</strong> - <code>alt</code> tags, <code>titles</code> etc. are all about accessibility, don't worry about them for SEO keywords as you will end up damaging usability. I know you didn't mention that but I thought I would put it in here for clarity.</p> <p class="cn"><strong>p.s.</strong> - 下一次,可能一次限制为 1 或 2 个问题,因为要回答的问题很多!<em class="showen"></em></p> <p class="en"><strong>p.s.</strong> - Next time, maybe limit this to 1 or 2 questions at once as that was a lot to answer!</p> <p>这篇关于内联 SVG &lt;标题&gt;&lt;描述&gt;可访问性的正确用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!</p> <div class="ax-break-text"><div class="ax-left"></div><span>The End</span><div class="ax-right"></div></div> <script src='https://www.womengda.cn/ads.php?id=15' language='javascript'></script> <div class="article-topic"> </div> <div class="ax-break"></div> <hr> </article> </section> <div class="ax-break"></div> <div class="title"><h4 class="bl">相关推荐</h4></div> <div class="ax-graphic"> <a href="/ask/web/68672.html" poster><img axLazyload src="/assets/images/default.png" data-src="/assets/images/default.png" alt="如何使用百度地图API获取地理位置信息" title="如何使用百度地图API获取地理位置信息"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/68672.html">如何使用百度地图API获取地理位置信息</a></h2></div> <div brief>首先,我们需要在百度地图开放平台上申请一个开发者账号,并创建一个应用。在创建应用的过程中,我们会得到一个密钥(ak),这是调用API的凭证。 接下来,我们需要准备一个PHP文件,以便可以在网页中调用。首先,我们需要引入百度地图API的JS文件,代码如下...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-11-22</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 244</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> <div class="ax-graphic"> <a href="/ask/web/68656.html" poster><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/2411/1-241114151952627-lp.png" alt="layui 实现实时刷新一个外部的div" title="layui 实现实时刷新一个外部的div"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/68656.html">layui 实现实时刷新一个外部的div</a></h2></div> <div brief>主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-11-14</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 156</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> <div class="ax-graphic"> <a href="/ask/web/68627.html" poster><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/2410/1-241024150A3152-lp.png" alt="layui要如何改变时间日历布局大小?" title="layui要如何改变时间日历布局大小?"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/68627.html">layui要如何改变时间日历布局大小?</a></h2></div> <div brief>问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-10-24</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 271</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> <div class="ax-graphic"> <a href="/ask/web/68613.html" poster><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/2410/1-24101QA942325-lp.png" alt="JavaScript小数运算出现多位的解决办法" title="JavaScript小数运算出现多位的解决办法"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/68613.html">JavaScript小数运算出现多位的解决办法</a></h2></div> <div brief>在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-10-18</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 301</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> <div class="ax-graphic"> <a href="/ask/web/68612.html" poster><img axLazyload src="/assets/images/default.png" data-src="/assets/images/default.png" alt="jQuery怎么动态向页面添加代码?" title="jQuery怎么动态向页面添加代码?"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/68612.html">jQuery怎么动态向页面添加代码?</a></h2></div> <div brief>append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-10-18</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 125</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> <div class="ax-graphic"> <a href="/ask/web/66788.html" poster><img axLazyload src="/assets/images/default.png" data-src="/assets/images/default.png" alt="正则表达式([A-Za-z])为啥可以匹配字母加数字或特殊符号?" title="正则表达式([A-Za-z])为啥可以匹配字母加数字或特殊符号?"/></a> <div class="ax-graphic-body"> <div caption><h2><a href="/ask/web/66788.html">正则表达式([A-Za-z])为啥可以匹配字母加数字或特殊符号?</a></h2></div> <div brief>问题描述: 我需要在我的应用程序中验证一个文本字段。它既不能包含数字,也不能包含特殊字符,所以我尝试了这个正则表达式:/[a-zA-Z]/匹配,问题是,当我在字符串的中间或结尾放入一个数字或特殊字符时,这个正则表达式依然可以匹配通过。 解决办法: 你应...</div> <div byline> <div class="ax-fleft"> <span class="mr5"><i class="ax-iconfont ax-icon-clock"></i> 2024-06-06</span> <span class="hidde"><i class="ax-iconfont ax-icon-leibie"></i> <a href="/ask/web/">前端开发问题</a></span> </div> <div class="ax-fright"><span><i class="ax-iconfont ax-icon-eye"></i> 165</span></div> </div> </div> </div> <div class="ax-break ax-hide-tel"></div> <hr class="ax-margin-lr" /> <div class="ax-break ax-hide-tel"></div> </div> <div class="ax-break"></div> <span class="ax-gutter"></span> <!--侧边栏区域--> <div class="ax-col ax-col-6"> <section class="box demo-section-border bg ax-shadow ax-radius-xs"> <div class="title bl"><h4>热门文章</h4></div> <a href="/ask/web/28832.html" class="ax-bulletin"><i rank="1">1</i><span class="ax-bulletin-body"><i caption>错误 [ERR_REQUIRE_ESM]:不支持 ES 模块的 require()</i></span></a> <a href="/ask/web/42008.html" class="ax-bulletin"><i rank="2">2</i><span class="ax-bulletin-body"><i caption>vue中yarn install报错:info There appears to be trouble with you</i></span></a> <a href="/ask/web/32630.html" class="ax-bulletin"><i rank="3">3</i><span class="ax-bulletin-body"><i caption>为什么 Chrome(在 Electron 内部)会突然重定向到 chrome-error://chromewebdat</i></span></a> <a href="/ask/web/46824.html" class="ax-bulletin"><i rank="4">4</i><span class="ax-bulletin-body"><i caption>“aria-hidden 元素不包含可聚焦元素"显示模态时的问题</i></span></a> <a href="/ask/web/28018.html" class="ax-bulletin"><i rank="5">5</i><span class="ax-bulletin-body"><i caption>使用选择器在 CSS 中选择元素的前一个兄弟</i></span></a> <a href="/ask/web/46573.html" class="ax-bulletin"><i rank="6">6</i><span class="ax-bulletin-body"><i caption>js报错:Uncaught SyntaxError: Unexpected string</i></span></a> <a href="/ask/web/46571.html" class="ax-bulletin"><i rank="7">7</i><span class="ax-bulletin-body"><i caption>layui怎么刷新当前页面?</i></span></a> <a href="/ask/web/40470.html" class="ax-bulletin"><i rank="8">8</i><span class="ax-bulletin-body"><i caption>将模式设置为“no-cors"时使用 fetch 访问 API 时出错</i></span></a> </section> <div class="ax-break"></div> <section class="box demo-section-border bg ax-shadow ax-radius-xs"> <div class="title bl"><h4>热门精品源码</h4></div> <div class="ax"> <ul class="ax-wall-2 ax-gap-xxs" ratio="8:10"> <li><a href="/dedecms/dedecms23281.html" title="大气响应式网络建站服务公司织梦模板"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/201117/1-20111GA3100-L.jpg"><i caption class="ax-ell">大气响应式网络建站服务公司织梦模板</i></a></li> <li><a href="/dedecms/dedecms6066.html" title="高端大气html5设计公司网站源码"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/150530/1-1505302212450-L.jpg"><i caption class="ax-ell">高端大气html5设计公司网站源码</i></a></li> <li><a href="/dedecms/dedecms17455.html" title="织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/161207/1-16120H219280-L.jpg"><i caption class="ax-ell">织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)</i></a></li> <li><a href="/dedecms/dedecms18954.html" title="财税代理公司注册代理记账网站织梦模板(带手机端)"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/171127/1-1G12H024130-L.jpg"><i caption class="ax-ell">财税代理公司注册代理记账网站织梦模板(带手机端)</i></a></li> <li><a href="/dedecms/dedecms23532.html" title="成人高考自考在职研究生教育机构网站源码(带手机端)"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/201207/1-20120GJ6300-L.jpg"><i caption class="ax-ell">成人高考自考在职研究生教育机构网站源码(带手机端)</i></a></li> <li><a href="/dedecms/dedecms19144.html" title="高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)"><img axLazyload src="/assets/images/default.png" data-src="/imgups/allimg/180112/1-1P1122033160-L.jpg"><i caption class="ax-ell">高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)</i></a></li> </ul> </div> </section> <div class="ax-break"></div> <script src='https://www.womengda.cn/ads.php?id=3' language='javascript'></script> <section class="box demo-section-border bg ax-shadow ax-radius-xs"> <div class="title bl"><h4>最新VIP资源</h4></div> <a href="/vip/html/html69001.html" class="ax-bulletin"><i rank="1">1</i><span class="ax-bulletin-body"><i caption>多功能实用站长工具箱html功能模板</i></span></a> <a href="/vip/html/html69000.html" class="ax-bulletin"><i rank="2">2</i><span class="ax-bulletin-body"><i caption>多风格简历在线生成程序网页模板</i></span></a> <a href="/vip/html/html68996.html" class="ax-bulletin"><i rank="3">3</i><span class="ax-bulletin-body"><i caption>论文相似度查询系统源码</i></span></a> <a href="/vip/html/html68995.html" class="ax-bulletin"><i rank="4">4</i><span class="ax-bulletin-body"><i caption>响应式旅游景点宣传推广页面模板</i></span></a> <a href="/vip/html/html68994.html" class="ax-bulletin"><i rank="5">5</i><span class="ax-bulletin-body"><i caption>在线起名宣传推广网站源码</i></span></a> <a href="/vip/html/html68993.html" class="ax-bulletin"><i rank="6">6</i><span class="ax-bulletin-body"><i caption>酷黑微信小程序网站开发宣传页模板</i></span></a> <a href="/vip/html/html68991.html" class="ax-bulletin"><i rank="7">7</i><span class="ax-bulletin-body"><i caption>房产销售交易中介网站模板</i></span></a> <a href="/vip/html/html68987.html" class="ax-bulletin"><i rank="8">8</i><span class="ax-bulletin-body"><i caption>小学作业自动生成程序</i></span></a> </section> </div> </div> </main> <script type="application/ld+json"> { "@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld", "@id": "https://www.womengda.cn/ask/web/50903.html", "appid": "否", "title": "内联 SVG &lt;标题&gt;&lt;描述&gt;可访问性的正确用法", "description": "Inline SVG lt;titlegt; lt;descgt; correct usage for accessilibility(内联 SVG lt;标题gt;lt;描述gt;可访问性的正确用法)", "image": "https://www.womengda.cn/assets/images/nopic.png", "pubDate": "2023-07-31 10:00:01" } </script> <!--页面底部版权区域--> <footer class="footer"> <div class="ax-break"></div> <div class="gotop"> <ul axShortcut="shape:'round',placement:'right-center'"> <li social><a class="ax-iconfont ax-icon-share"></a><span pop axShare><a class="ax-iconfont ax-icon-qq-f" share="qq"></a><a class="ax-iconfont ax-icon-weibo-f" share="weibo"></a><a class="ax-iconfont ax-icon-qzone-f" share="qzone"></a><a class="ax-iconfont ax-icon-facebook-f" share="facebook"></a></span></li> <li totop><a class="ax-iconfont ax-icon-totop"></a></li> </ul> </div> <div class="ax-footer"> <div class="ax-row ax-split box bg ax-shadow-primary"> <div class="ax-col ax-copyright">Copyright © 2025-2026 沃梦达建站 All Rights Reserved.</div> <div class="ax-operate"> <a href="/about/" rel="nofollow" class="ax-btn ax-line ax-sm ax-icon ax-round" title="关于我们"><i class="ax-iconfont ax-icon-about"></i></a> <a href="/about/ad/" rel="nofollow" class="ax-btn ax-line ax-sm ax-icon ax-round" title="最新公告"><i class="ax-iconfont ax-icon-contact"></i></a> </div> </div> </div> </footer> <div class="id" id="search" style="display:none;"> <form action="https://www.womengda.cn/search.php" method="GET" > <div class="ax-search ax-round"> <div class="ax-search-body"> <i class="ax-iconfont ax-icon-search" legend></i> <input name="s" placeholder="请输入关键词..." type="text"> </div> <a onclick="submitForm(event)" class="ax-search-footer">搜索</a> </div> </form> <div class="ax-break"></div> </div> <div style="display:none;"> <script src="https://www.womengda.cn/assets/js/wmd.min.js" type="text/javascript" charset="utf-8" ></script> </div> <script type="text/javascript" src="https://www.womengda.cn/assets/js/highlight.min.js"></script> <script type="text/javascript" src="https://www.womengda.cn/assets/js/prism.min.js"></script> <script type="text/javascript" src="https://www.womengda.cn/assets/js/prism.js"></script> <script>(function(){window.id=50903;var cltj=document.createElement("script");cltj.src="https://www.womengda.cn/visits/?v=10.0";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(cltj,s);})();</script></body> </html>