Last active
August 1, 2020 21:57
-
-
Save MattOnyx/667348abb98fa369901848025f317e42 to your computer and use it in GitHub Desktop.
Full code sample for my Medium article: You Should Style the Wrong Button State
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
button { | |
position: relative; | |
margin: 2em; | |
padding: 1em 2em; | |
background-color: hsl(0, 0%, 100%); | |
border: none; | |
border-radius: 5px; | |
box-shadow: 0 0 0 0px hsla(220, 80%, 70%, 1), 0 4px 5px 1px hsla(0, 0%, 10%, 0.1); | |
color: hsl(0, 0%, 10%); | |
font-weight: bold; | |
letter-spacing: 2px; | |
transition: box-shadow 100ms ease-out, background-color 100ms ease-out; | |
} | |
/* USUAL FEEDBACK */ | |
button:hover, button:focus, button:active { | |
outline: none; | |
} | |
button:hover { | |
cursor: pointer; | |
background-color: hsl(220, 80%, 97%); | |
} | |
button:active { | |
background-color: hsl(220, 80%, 94%); | |
} | |
button:focus, button:active { | |
box-shadow: 0 0 0 4px hsla(220, 80%, 70%, 1), 0 4px 5px 1px hsla(0, 0%, 10%, 0.1); | |
} | |
/* PULSE EFFECT */ | |
button::before { | |
content: " "; | |
position: absolute; | |
top: 1px; | |
bottom: 1px; | |
left: 1px; | |
right: 1px; | |
border-radius: 10px; | |
background-color: hsla(230, 80%, 80%, 1); | |
opacity: 1; | |
z-index: -1; | |
pointer-events: none; | |
} | |
button:not(:active)::before { | |
transition: all 0.3s ease-out, opacity 0.2s 0.1s ease-out; | |
top: -20px; | |
bottom: -20px; | |
left: -20px; | |
right: -20px; | |
opacity: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment