Created
February 3, 2025 19:45
-
-
Save treetop1500/f307a4cf4b34fd90e8ca4e84be4647d5 to your computer and use it in GitHub Desktop.
Hidden Skip Links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!-- HTML --> | |
<a href="#main-content" class="skip-link">Skip to main content</a> | |
<nav> | |
<!-- Your navigation content --> | |
</nav> | |
<main id="main-content" tabindex="-1"> | |
<!-- Your main content --> | |
</main> | |
<!-- CSS --> | |
<style> | |
.skip-link { | |
/* Position the link */ | |
position: absolute; | |
top: -100px; | |
left: 0; | |
z-index: 100; | |
/* Basic styling */ | |
background: #ffffff; | |
color: #000000; | |
padding: 10px 20px; | |
text-decoration: none; | |
/* Ensure proper width for longer text */ | |
width: auto; | |
height: auto; | |
margin: 0; | |
/* Add a border when focused */ | |
border: 2px solid transparent; | |
/* Transition for smooth appearance */ | |
transition: top 0.3s ease; | |
} | |
/* Show the link when it receives focus */ | |
.skip-link:focus { | |
top: 0; | |
border-color: #000000; | |
outline: none; | |
} | |
/* Ensure main content can receive focus */ | |
main:focus { | |
outline: none; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment