I have a div .boxthat has an absolute position set at the bottom of the parent div. It does not have a top position because the height is different for different divs .box. When hovering over the parent div, I want to change its position topto 0 with the transition effect.
In the following code, the transition does not work unless I define the top position by default. I tried to use top: autoand it still does not work. How to use the transition without determining the top position.
Here is my code:
HTML:
<div class="wrap">
<div class="box">
Box
</div>
</div>
CSS
.wrap{
position: relative;
height: 200px;
width: 200px;
background: green;
}
.box{
background: yellow;
position: absolute;
bottom: 0;
left: 0;
transition: all 0.9s ease 0s;
top: 50%;
}
.wrap:hover .box{
top: 0;
bottom: 0;
}
Fiddle: http://jsfiddle.net/5hs09apn/
source
share