CSS에서 요소 숨기기: 접근 가능한 방법
UI에서 요소를 숨기는 것은 흔한 일이지만, 접근 가능한 방식으로 그렇게 하면 의도치 않게 일부 사용자를 제외하는 일이 발생하지 않습니다. 이 기사에서는 세 가지 시나리오를 다룹니다.
- 스크린 리더에서 요소를 숨깁니다.
- 스크린 리더에만 요소를 표시합니다.
- 스크린 리더를 포함한 모든 사용자에게 요소를 숨깁니다.
각 섹션에는 코드 예제와 실제 사용 사례가 포함되어 있습니다
스크린 리더에서 요소 숨기기
눈이 있는 사용자에게는 요소가 표시되지만 스크린 리더에서는 요소가 숨겨지도록 하려면 aria-hidden="true" 속성이나 CSS를 사용할 수 있습니다.
<div aria-hidden="true">This content is hidden from screen readers.</div>
사용 사례
- 배경 이미지 숨기기
- 의미 있는 정보를 전달하지 않는 장식적인 아이콘이나 시각적 요소.
<button> <span aria-hidden="true">+</span> Add Item </button>
스크린 리더에만 요소 표시
화면 판독기에는 요소가 표시되지만 시력이 있는 사용자에게는 표시되지 않게 하려면 '시각적으로 숨김' 기술을 사용할 수 있습니다. Tailwind CSS는 이러한 목적으로 사전 빌드된 sr 전용 유틸리티 클래스를 제공합니다.
<div> <p>Writing the sr-only class in CSS would look like this<br> </p> <pre class="brush:php;toolbar:false">.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
사용 사례
-
텍스트를 시각적으로 표시하지 않고 입력과 같은 대화형 요소에 레이블을 지정하는 경우:
<label for="username" class="sr-only">Username</label> <input type="text">
로그인 후 복사 -
Providing additional information for screen reader users using aria-describedby
<div class="sr-only">
로그인 후 복사 Hiding Input Elements for Custom Radio Buttons
When creating custom radio buttons (or checkboxes), you often hide the native input element and replace it with a visually styled element. To do this accessibly, the hidden input must remain visible to screen readers.
Hiding Elements from All Users
To completely hide an element from both sighted users and screen readers, you can use display: none or visibility: hidden.
.hidden { display: none; /* or visibility: hidden; */ }
수업 적용:
<div> <h2> TL;DR </h2> <p>다음은 다양한 CSS 속성이 다양한 유형의 사용자 가시성에 어떤 영향을 미치는지 요약한 표입니다.</p><div><table> <thead> <tr> <th><strong>CSS Attribute</strong></th> <th><strong>Hides for All Users</strong></th> <th><strong>Hides for Sighted Users</strong></th> <th><strong>Hides for Screen Readers</strong></th> <th><strong>Notes</strong></th> </tr> </thead> <tbody> <tr> <td>display: none</td> <td>✅</td> <td>✅</td> <td>✅</td> <td>Completely removes the element from the visual and accessibility tree.</td> </tr> <tr> <td>visibility: hidden</td> <td>✅</td> <td>✅</td> <td>✅</td> <td>Hides the element visually but keeps it in the layout and accessibility tree.</td> </tr> <tr> <td>opacity: 0</td> <td>❌</td> <td>✅</td> <td>❌</td> <td>Makes the element fully transparent but still visible to screen readers and interactive.</td> </tr> <tr> <td>clip: rect(0, 0, 0, 0)</td> <td>✅</td> <td>✅</td> <td>❌</td> <td>Commonly used in the "visually hidden" technique; removes visual rendering but accessible.</td> </tr> <tr> <td>position: absolute; width: 1px; height: 1px;</td> <td>✅</td> <td>✅</td> <td>❌</td> <td>Used with the "visually hidden" technique; keeps elements accessible to screen readers.</td> </tr> <tr> <td>aria-hidden="true"</td> <td>❌</td> <td>❌</td> <td>✅</td> <td>Removes the element from the accessibility tree but leaves it visually present.</td> </tr> <tr> <td>overflow: hidden</td> <td>❌</td> <td>✅ (if out of bounds)</td> <td>❌</td> <td>Hides content visually if it overflows the container but does not affect screen readers.</td> </tr> <tr> <td>height: 0; width: 0;</td> <td>✅</td> <td>✅</td> <td>❌</td> <td>Hides content visually while keeping it accessible to screen readers.</td> </tr> <tr> <td>z-index: -1</td> <td>❌</td> <td>✅</td> <td>❌</td> <td>Moves the element behind others, making it invisible to sighted users but screen reader-accessible.</td> </tr> <tr> <td>opacity: 0; pointer-events: none;</td> <td>✅</td> <td>✅</td> <td>❌</td> <td>Makes an element fully transparent and non-interactive, but accessible to screen readers.</td> </tr> </tbody> </table></div>
위 내용은 CSS에서 요소 숨기기: 접근 가능한 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

새로운 프로젝트가 시작될 때, Sass 컴파일은 눈을 깜박이게합니다. 특히 BrowserSync와 짝을 이루는 경우 기분이 좋습니다.

이번 주에 플랫폼 뉴스 라운드 업 RONDUP, Chrome은로드에 대한 새로운 속성, 웹 개발자를위한 접근성 사양 및 BBC Move를 소개합니다.

이것은 처음으로 HTML 요소를보고 있습니다. 나는 그것을 잠시 동안 알고 있었지만 아직 스핀을 위해 그것을 가져 갔다. 그것은 꽤 시원하고 있습니다

구매 또는 빌드는 기술 분야의 고전적인 논쟁입니다. 신용 카드 청구서에 라인 항목이 없기 때문에 물건을 구축하는 것이 저렴할 수 있지만

한동안 iTunes는 팟 캐스팅에서 큰 개 였으므로 "Podcast 구독"을 링크 한 경우 다음과 같습니다.

이번 주에 타이포그래피를 검사하기위한 편리한 북마크 인 Roundup, JavaScript 모듈과 Facebook의 Facebook 등을 어떻게 가져 오는지 땜질하기 위해 대기하는 편리한 북마크 인 Roundup과 Facebook의

사이트에서 방문자 및 사용 데이터를 추적하는 데 도움이되는 분석 플랫폼이 많이 있습니다. 아마도 널리 사용되는 Google 웹 로그 분석
