Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css transition on element that changes position on mousehover

Tags:

css

I have a Box that elevates when the user has his mouse hovering this box, and I do this with :

.box:hover { 
     position: relative; 
     top: -10px;
}

I would like to know if it possible to make a smooth transition with the transition property ?

If not, How should i go about getting this smooth effect ?

like image 516
Jackymamouth Avatar asked Jun 19 '26 14:06

Jackymamouth


1 Answers

You can use the CSS transition property. Read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions

Here is an example:

.box {
  background: red;
  height: 50px;
  position: relative;
  top: 50px;
  transition: top 1000ms ease-in;
  width: 50px;
}
.box:hover {
  position: relative;
  top: 0;
}
<div class="box">Hey</div>
like image 69
Red2678 Avatar answered Jun 23 '26 07:06

Red2678



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!