I'm having trouble figuring out why the car in my animation isn't swerving around the middle line. It seems to be veering a bit off to the right?
.car {
width: 40px;
height: 60px;
background: #f00;
left: 50%;
transform: translate(-50%, 0);
animation: swerve 2s linear infinite;
top: 10%;
position: absolute;
}
@keyframes swerve {
0% {
transform: translate(-50%, 0);
}
50% {
transform: translate(50%, 0);
}
}
.road {
width: 200px;
background: black;
height: 500px;
display: block;
position: relative;
}
.road-middle {
border: 1px dotted #fff;
transform: rotate(90deg);
display: block;
position: relative;
top: 200px;
}
<div class='road'>
<span class="road-middle"></span>
<div class='car'></div>
</div>
Additionally, is there a way to adjust the length of the middle line's border?