Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Transition Ease in and out Box Shadow

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?

like image 918
Tom Pinchen Avatar asked Apr 23 '13 07:04

Tom Pinchen


People also ask

Does transition work with box shadow?

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.

What does the css3 attribute box shadow effect?

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.

What is ease in transition CSS?

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.


2 Answers

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>
like image 123
Mr. Alien Avatar answered Nov 11 '22 05:11

Mr. Alien


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; } 
like image 30
mPrinC Avatar answered Nov 11 '22 07:11

mPrinC