rufus
rufus

Reputation: 857

CSS ease in and out on hover

I have a simple div that is round with a border-radius of 50%. On hover the border radius changes to zero. I have used the following css code which works perfectly.

.design-box {
  width: 100%;
  height: 250px;
  margin: 100px auto;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  position: relative;
}

.design-box:hover {
  border-radius: 0;
  -webkit-transition: all 1s ease;
  transition: all 1s ease;
}
<div class="design-box"></div>

What I would like to happen is that when the div is no longer hovered I would like the transition to ease out and slowly transform back to the original border-radius of 50%. I cant quite get it to work, am I missing a simple step here?

Thank you

Upvotes: 9

Views: 39992

Answers (1)

Saurav Rastogi
Saurav Rastogi

Reputation: 9731

Put transition only on the normal state:

.design-box {
  transition: all 1s ease;
}

Have a look at the snippet below:

.design-box {
  width: 100%;
  height: 250px;
  margin: 100px auto;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  position: relative;
  transition: all 1s ease;
}

.design-box:hover {
  border-radius: 0;
}
<div class="design-box"></div>

Upvotes: 28

Related Questions