Snippets

kate deibel Hidden Skip Links that Animate into View on Focus

Created by kate deibel
/* stylize the skip links (search box and main content) to appear when focused */
a.skipLink  {
    font-size: 0.9em; /* older browser compatibility */
    font-size: 0.9rem;
    display: inline-block;
    moz-box-sizing: border-box;
        box-sizing: content-box;
    line-height: 1;
    margin: 0;
    padding: 0.5em 12px 0.5em 0.5em;
    padding: 0.5em calc(0.25em + 8px) 0.5em 0.5em;
    position: absolute;
    top: 0;
    left: -12em;
    color: transparent;
    background: transparent;
    -webkit-transition: left .5s ease-out, background .25s linear;
            transition: left .5s ease-out, background .25s linear;
    overflow: hidden;
    pointer-events: none;
    transform: translate3d(0,0,0);
    font-weight: bold;
    z-index: 1000;
}
a.skipLink:hover {
    text-decoration: underline;
    left: 0;
    outline: 0;
    width: auto;
    height: auto;
}
a.skipLink:visited {
    left: 0;
    outline: 0;
    width: auto;
    height: auto;
}
a.skipLink:focus {
    pointer-events: auto;
    margin: 0;
    position: absolute;
    background: #165788;
    color: white;
    outline:0;
    left: 0;
    -webkit-transition: left .5s ease-in, background .25s linear;
            transition: left .5s ease-in, background .25s linear;
}

/* Below is how I stack two skip links so they don't overlap when animating */
a.skipLink {
    top: 0;
}
a.skipLink + a.skipLink {
    top: 1.9em;
    top: calc(0.9rem + 1em);
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.