Просто добавьте top: 75px
к ключевому кадру , так как изменение height
равно 50px
.Вы хотите уменьшить height
на 25px или половину с обеих сторон, верх и низ , чтобы достичь желаемого значения 10px
.Итак 50px / 2 + top: 50px
= top: 75px
:
.toggle {
position: absolute;
width: 400px;
height: 200px;
background: #ccc;
}
.left-border {
position: absolute;
top: 50px; /* starting position from the top */
left: 10px;
width: 20px;
height: 60px;
border-radius: 200px;
background-color: #f00;
animation: height 2s;
}
@-webkit-keyframes height {
to {height: 10px; top: 75px} /* + ending position from the top */
}
<div class="toggle">
<div class="left-border"></div>
</div>