视觉隐藏

使用这些辅助类在视觉上隐藏元素,同时保持其对辅助技术的可访问性。

On this page

使用 .visually-hidden 在视觉上隐藏元素,同时仍允许其暴露给辅助技术(例如屏幕阅读器)。使用 .visually-hidden-focusable 可默认在视觉上隐藏元素,但在其获得焦点时(例如由仅使用键盘的用户)显示它。.visually-hidden-focusable 也可以应用于容器——得益于 :focus-within,当容器中的任何子元素获得焦点时,该容器将会显示。

Title for screen readers

Skip to main content
A container with a focusable element.
HTML
<h2 class="visually-hidden">Title for screen readers</h2>
<a class="visually-hidden-focusable" href="#content">Skip to main content</a>
<div class="visually-hidden-focusable">A container with a <a href="#">focusable element</a>.</div>

visually-hidden 和 visually-hidden-focusable 也可以作为 mixin 使用。

SCSS
          // Usage as a mixin

.visually-hidden-title {
  @include visually-hidden;
}

.skip-navigation {
  @include visually-hidden-focusable;
}