I'm trying to create a text highlight animation in css like the one in this gif. From left to right continuously.
I tried this
<p>
The <span class="test">world</span>
</p>
.test {
background: linear-gradient(to top, red 50%, transparent 50%);
animation-name: highlight;
animation-duration: 1s;
animation-iteration-count: infinite;
}
@keyframes highlight {
0% {
background-size: 0;
background-position: -100%, 0;
}
50% {
background-size: 100%;
background-position: 100%, 100%;
}
}
But it's giving some weird glitch effect instead. What am I doing wrong and how to achieve this?