I donโt know why you need animations when you can just achieve the above using transitions
The trick is moving the child when the parent hangs
Demo
div { margin: 100px; position: relative; border: 1px solid #aaa; height: 30px; } div span { position: absolute; left: 0; width: 100px; background: #fff; top: 0; -moz-transition: all 1s; -webkit-transition: all 1s; transition: all 1s; } div span:nth-of-type(1) { z-index: 1; } div:hover span:nth-of-type(1) { top: -40px; }
Explanation: First, we end the span
inside the div
element, which is equal to position: relative;
and later we use transition
on the span
, which will help us smooth out the animation
stream, now we use position: absolute;
with left: 0;
, this will stack the elements on top of each other, than we use z-index
so that the first element overlaps the second.
Now, finally, we move the first span
, we select it with nth-of-type(1)
, which is nothing more than the first child of the view, which is nested inside the div
, and we assign top: -40px;
which will pass when the parent div
frozen.
source share