I have a text animation that scrolls text from left to right and back so the full text can be seen and isn't cut off. I have an example below:
.selectionContainer {
max-width: 150px;
overflow: hidden;
}
.link {
white-space: nowrap;
display: inline-flex;
overflow: visible !important;
}
.link_animated {
animation: backAndForth 5s linear infinite;
}
@keyframes backAndForth {
0% {
transform: translateX(0);
}
10% {
transform: translateX(0);
}
45% {
transform: translateX(-50%);
}
55% {
transform: translateX(-50%);
}
90% {
transform: translateX(0);
}
100% {
transform: translateX(0);
}
}
.HS-Silk-Image {
height: 30px;
width: 30px;
}
<table id="column-1-table" class="table HS-Table">
<tbody>
<tr>
<td class="" colspan="4">
<div class="">Monday</div>
<div class="HS-Going-Text">2022-06-20</div>
</td>
<td class="" colspan="3">
</tr>
<tr class="" style="overflow-x:hidden;">
<td class="" colspan="4">
<div class="pull-left Selection-Container">Argentina Liga Profesional de Futbol</div>
</td>
</tr>
<tr data-selectionnumber="0" class="Event-bt9305886 RowVisible" id="Event-bt9305886">
<td class="">
<div class="">20:30</div>
</td>
<td class="">
<div class=""><img class="HS-Silk-Image" src="https://dimg-pa.googleapis.com/lg/CgYwMDAwMDA.png?sig=AI8nk_dGt7qwEVp9ek4ARNvpY1gz&key=AIzaSyCUqbG5Kw_8jb3cy2ZBKvV2kAi8z0qmQO0&sk=r7Evjfpq7nk&w=96&h=96"></div>
</td>
<td class="selectionContainer">
<div class="link link_animated">Godoy Cruz v Defensa y Justicia</div>
</td>
<td class="">
<div class=""><img class="HS-Silk-Image" src="https://dimg-pa.googleapis.com/lg/CgYwMDAwMDA.png?sig=AI8nk_dGt7qwEVp9ek4ARNvpY1gz&key=AIzaSyCUqbG5Kw_8jb3cy2ZBKvV2kAi8z0qmQO0&sk=r7Evjfpq7nk&w=96&h=96"></div>
</td>
</tr>
</tbody>
</table>
This works fine, however I need the translateX amount in the animation to be based on the width of the text, otherwise the text scrolls too far and shows whitespace.
Perhaps I need to use a bit of JS to get the width of the text or perhaps there is better way to get what im trying to achieve in CSS?