Skip to content

Instantly share code, notes, and snippets.

@ZhenDeng
Created January 19, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhenDeng/423caac67e44268933419f014e16c622 to your computer and use it in GitHub Desktop.
Save ZhenDeng/423caac67e44268933419f014e16c622 to your computer and use it in GitHub Desktop.
**** HTML
** Important: add tabindex="-1" to child tag
<button id="btn" class="btn" type="button">
<span class="btn__content" tabindex="-1">
I'm a button!
</span>
</button>
<a class="btn" href="#x">
<span class="btn__content" tabindex="-1">
I'm a link!
</span>
</a>
<span class="btn" tabindex="0">
<span class="btn__content" tabindex="-1">
I'm a span!
</span>
</span>
**** CSS:
/* All the states on the inner element */
.btn:hover > .btn__content {
background: salmon;
}
.btn:active > .btn__content {
background: darkorange;
}
.btn:focus > .btn__content {
box-shadow: 0 0 2px 2px #51a7e8;
color: lime;
}
/* Removing default outline only after we've added our custom one */
.btn:focus,
.btn__content:focus {
outline: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment