简体   繁体   English

SVG文本可访问性

[英]SVG text accessibility

I have the following structure 我有以下结构

 <h2> <svg viewBox='-5 -40 100 50'> <!-- some filters that get applied on the elements below --> <clipPath id='c'> <text id='t'>Scooby</text> </clipPath> <g clip-path='url(#c)'> <rect x='-5' y='-40' width='100%' height='100%'/> <path/> </g> <use xlink:href='#t'/> <use xlink:href='#t'/> </svg> </h2> 

How can I ensure the text inside the clipPath ("Scooby") gets seen by screen readers and only once ? 我怎样才能确保text里面clipPath (“史酷比”)获取屏幕阅读器和只有一次见过?

I know SVG text should be read by screen readers, but is that the still the case when it's inside a clipPath element? 我知道屏幕阅读器应该读取SVG text ,但是当它在clipPath元素中时仍然是这样吗? And what about use copies of it? 那么use它的副本呢?

I'm using this structure in order to get some fancy effects (think stuff like this ) on the heading text (and ditch the .jpg image that's currently used). 我正在使用这种结构,以便在标题文本上获得一些奇特的效果(想想这样的东西 )(并抛弃当前使用的.jpg图像)。

Remove the SVG from your screenreader using aria-hidden and define the label for your h2 using aria-labelledby . 使用aria-hidden从屏幕阅读器中删除SVG,并使用aria-labelledbyh2定义标签。

<h2 aria-labelledby="t">
  <svg viewBox='-5 -40 100 50' aria-hidden="true">
    <!-- some filters that get applied on the elements below -->

    <clipPath id='c'>
      <text id='t'>Scooby</text>
    </clipPath>

    <g clip-path='url(#c)'>
      <rect x='-5' y='-40' width='100%' height='100%'/>
      <path/>
    </g>

    <use xlink:href='#t'/>
    <use xlink:href='#t'/>
  </svg>
</h2>

Add aria-hidden to suppress screen reading on specific elements, it'll read "Scooby" just once: 添加aria-hidden抑制特定元素的屏幕阅读,它只会读取“Scooby”一次:

<h2>
  <svg viewBox='-5 -40 100 50'>
    <!-- some filters that get applied on the elements below -->

    <clipPath id='c'>
      <text id='t'>Scooby</text>
    </clipPath>

    <g clip-path='url(#c)'>
      <rect x='-5' y='-40' width='100%' height='100%'/>
      <path/>
    </g>

    <use aria-hidden="true" xlink:href='#t'/>
    <use aria-hidden="true" xlink:href='#t'/>
  </svg>
</h2>

The aria-label attribute is intended for use when text is not visible on screen aria-label属性适用于屏幕aria-label不到文本的情况

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute

<h2 aria-label="Scooby">
  <svg> ... </svg>
<h2>

or alternatively, I believe most screen readers will use the <title> SVG element. 或者,我相信大多数屏幕阅读器都会使用<title> SVG元素。

<h2>
  <svg>
    <title>Scooby logo</title>
    ...
  </svg>
<h2>

You also have the option of using other ARIA attributes, such as aria-labelledby . 您还可以选择使用其他ARIA属性,例如aria-labelledby

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

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