How to make screenreader read different text in div

↘锁芯ラ 提交于 2019-12-11 17:03:26

问题


I have a div like this: <div class="whatever">17:03</div>

And when someone using a screen reader hovers over that text, I'd like it to read "17 minutes and 3 seconds"

What's the standard practice for doing this?


回答1:


You can include some additional text for screenreader only:

<div class="whatever">17<span class="sr-only"> minutes and </span>:03<span class="sr-only">seconds</span></div>

and CSS (taken from Bootstrap 3)

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}



回答2:


I ended up just making the English text the Aria Label, as this div was inside of an tag, so it's information ended up being read by the screenreader when it was in the aria label, without creating any extra tab targets.



来源:https://stackoverflow.com/questions/48955075/how-to-make-screenreader-read-different-text-in-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!