This content originally appeared on Ugly Duck and was authored by Ugly Duck
Everyone can appreciate fancy, animated buttons - but often times they come with a performance cost: JavaScript. Luckily for us, we can create our very own shiny, animated buttons with pure CSS.
The Demo
See the Pen Shiny Buttons by Bradley Taunt (@bradleytaunt) on CodePen.
The HTML
Nothing fancy going on here, just a set of ahref
elements with specific button
classes added:
The CSS
First we set the default base styling for all the buttons. We also place the inner text into span
elements (I will explain why in a little bit):
Now we need to create our shiny element that will pass across the button on hover
or focus
. For this object we will use the before
pseudo element:
Next, we tell the before
element to swipe across the main .button
parent element when the user hovers or focuses on it. Remember placing our inner content into a span
element? That insures that our shiny/swipe element doesn’t position itself over the text, but instead flows under it:
All that’s left is adding some visual flare to each individual button - in this case background-color and border-color:
Browser Support
These buttons work across all browsers flawlessly. See the details on the caniuse report itself.
The Live CodePen
You can find the live demo embedded at the top of this post, or directly on CodePen here.
This content originally appeared on Ugly Duck and was authored by Ugly Duck
Ugly Duck | Sciencx (2021-04-27T00:00:00+00:00) Shiny, Animated CSS Buttons. Retrieved from https://www.scien.cx/2021/04/27/shiny-animated-css-buttons/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.