I want to animate borders of an element using CSS3, whether it's in hover state or normal state. Can someone provide me a code snippet for this or can guide?
I can do this using jQuery but looking for some pure CSS3 solution.
CSS border animation is useful for giving a border image or container element a unique style. To make a website's user interface (UI) more attractive, use a CSS border animation design. CSS border animation is useful for giving a border image or container element a unique style.
The first thing is to create a border with a transparent background. Then animate it over hover giving it a linear animation and an identifier name as animate. Now using keyframes we will animate the border. Make sure to apply color to only the top and right side of the border.
Definition and Usage. Some CSS properties are animatable, meaning that they can be used in animations and transitions. Animatable properties can change gradually from one value to another, like size, numbers, percentage and color.
You can use a CSS3 transition
for this. Have a look at this example:
http://jsfiddle.net/ujDkf/1/
Here is the main code:
#box { position : relative; width : 100px; height : 100px; background-color : gray; border : 5px solid black; -webkit-transition : border 500ms ease-out; -moz-transition : border 500ms ease-out; -o-transition : border 500ms ease-out; transition : border 500ms ease-out; } #box:hover { border : 10px solid red; }
You can try this also...
button { background: none; border: 0; box-sizing: border-box; margin: 1em; padding: 1em 2em; box-shadow: inset 0 0 0 2px #f45e61; color: #f45e61; font-size: inherit; font-weight: 700; vertical-align: middle; position: relative; } button::before, button::after { box-sizing: inherit; content: ''; position: absolute; width: 100%; height: 100%; } .draw { -webkit-transition: color 0.25s; transition: color 0.25s; } .draw::before, .draw::after { border: 2px solid transparent; width: 0; height: 0; } .draw::before { top: 0; left: 0; } .draw::after { bottom: 0; right: 0; } .draw:hover { color: #60daaa; } .draw:hover::before, .draw:hover::after { width: 100%; height: 100%; } .draw:hover::before { border-top-color: #60daaa; border-right-color: #60daaa; -webkit-transition: width 0.25s ease-out, height 0.25s ease-out 0.25s; transition: width 0.25s ease-out, height 0.25s ease-out 0.25s; } .draw:hover::after { border-bottom-color: #60daaa; border-left-color: #60daaa; -webkit-transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s; transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s; }
<section class="buttons"> <button class="draw">Draw</button> </section>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With