I am trying to get div id to ease in and out of a box shadow using CSS3.
The current CSS I have is:
#how-to-content-wrap-first:hover { -moz-box-shadow: 0px 0px 5px #1e1e1e; -webkit-box-shadow: 0px 0px 5px #1e1e1e; box-shadow: 0px 0px 5px #1e1e1e; -webkit-transition: box-shadow 0.3s ease-in-out 0s; -moz-transition: box-shadow 0.3s ease-in-out 0s; -o-transition: box-shadow 0.3s ease-in-out 0s; -ms-transition: box-shadow 0.3s ease-in-out 0s; transition: box-shadow 0.3s ease-in-out 0s; }
The issue I am having is that on the first hover of the element there is no easing in or out and then any subsequent hovers ease in but do not ease out.
Any advice people have would be much appreciated?
Adding a CSS transition to animate the box-shadow of an element is a handy trick. It's a design technique that's often used on hover to highlight something. If you've used this effect you might have noticed that sometimes the performance can be sub optimal making the animation slow.
The box-shadow property enables you to cast a drop shadow from the frame of almost any element. If a border-radius is specified on the element with a box shadow, the box shadow takes on the same rounded corners.
ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default) linear - specifies a transition effect with the same speed from start to end.
You need to use transitions on .class
and not .class:hover
div { height: 200px; width: 200px; box-shadow: 0; transition: box-shadow 1s; border: 1px solid #eee; } div:hover { box-shadow: 0 0 3px #515151; ; }
<div></div>
Here is a resource-efficient solution
#how-to-content-wrap-first::after{ /* Pre-render the bigger shadow, but hide it */ box-shadow: 3px 3px 5px -1px #80aaaa; opacity: 0; transition: opacity 0.3s ease-in-out; } #how-to-content-wrap-first:hover::after { /* Transition to showing the bigger shadow on hover */ opacity: 1; }
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