可访问性 - 可访问线路断路的标题?

发布于 2025-02-08 09:29:13 字数 507 浏览 0 评论 0原文

情况:我必须在标题中迫使线路破裂。

The quick brown fox
jumps over the lazy dog

我可以做< h1> Quick Brown Fox< br/>跳过懒惰的狗</h1>,但是屏幕阅读器将其解释为“标题1,2个项目”。屏幕阅读器是否有办法不阅读它?

我有这样的解决方案:

<h1 aria-hidden="true">The quick brown fox<br/> jumps over the lazy dog</h1>
<h1 class="sr-only">The quick brown fox jumps over the lazy dog</h1>

2个HTML元素,一个用于“为非视野障碍的用户进行线路休息”,另一个用于“不为非视觉损害的用户进行线路休息”。这里有更好的方法吗?

Situation: I have to force line-breaks in a heading.

The quick brown fox
jumps over the lazy dog

I can do <h1>The quick brown fox<br/> jumps over the lazy dog</h1>, but a screen-reader will interpret it as "heading level 1, 2 items". Is there a way for the screen reader to not read it?

I have this solution:

<h1 aria-hidden="true">The quick brown fox<br/> jumps over the lazy dog</h1>
<h1 class="sr-only">The quick brown fox jumps over the lazy dog</h1>

2 HTML elements, one for "doing a line break for non-visually impaired users", and one for "not doing a line break for non-visually impaired users". Is there a better approach here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山人契 2025-02-15 09:29:13

我猜有两个选择

.slogan { white-space: pre }
<h1 class="slogan">The quick brown fox
jumps over the lazy dog</h1>

将保留空白。这是一个缺点,即它不适合其与字体大小的容器的宽度,从而使可访问性更具降级。如果您确定您的文本会通过 wcag的成功标准。 /a>,这可能是一种选择。

至少在NVDA中起作用的更灵活的解决方案是添加一个pseudo块元素宽度高度0

.newline::before { content: ""; display: block; height: 0; }
<h1>The quick brown fox
<span class="newline">jumps over the lazy dog</span></h1>

There are two options I guess

.slogan { white-space: pre }
<h1 class="slogan">The quick brown fox
jumps over the lazy dog</h1>

will preserve the white space as-is. This has the disadvantage that it’s not adjusting to it’s container’s width in relation to the font-size any more, degrading accessibility. If you’re sure your text will pass WCAG’s Success Criterion 1.4.10: Reflow, that might be an option.

The more flexible solution, that works in NVDA at least, is to add a pseudo block element width height 0.

.newline::before { content: ""; display: block; height: 0; }
<h1>The quick brown fox
<span class="newline">jumps over the lazy dog</span></h1>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文