Created
January 19, 2020 22:45
-
-
Save ZhenDeng/423caac67e44268933419f014e16c622 to your computer and use it in GitHub Desktop.
This file contains 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 | |
** 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