I'm attempting to create a scrolling effect where the text moves back and forth within its container. The current issue I'm facing is that the text goes beyond the width of the parent container before scrolling back. I want the text to smoothly scroll from left to right and right to left as soon as it reaches the edges of the container.
Can someone assist me in modifying the code below so that I can achieve the desired result:
.text_scroll {
border: 1px solid #ddd;
overflow: hidden;
white-space: nowrap;
}
.text_scroll_alt > p {
width: max-content;
padding-left: 100%;
border: 1px solid red;
animation: scroll_alt 5s linear infinite alternate;
}
@keyframes scroll_alt {
to {transform: translateX(-100%);}
}
<div class="text_scroll text_scroll_alt">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>