I'm currently working on a hover effect that is functioning properly. However, I am attempting to set a fixed width for the blue line, such as a maximum width of 100px. Whenever I try to modify the code below by adding the width constraint, the animation stops working and the growth does not occur from the center.
Does anyone have suggestions on how to adjust the code so that it smoothly animates from the center to a fixed width?
body {
width:100%;
}
div {
display:block;
position:absolute;
top:45%;
left:50%;
border-bottom:4px solid blue;
width:0%;
text-align:center;
animation: line 2s linear forwards;
}
@keyframes line {
from {
left:50%;
width:0%;
}
to {
left:5%;
width:90%;
}
}
<div>Heading</div>