Adjust your code like below:
Removed uncessary code to keep only the relevant one
body {
background: pink;
}
.box {
color: #fff;
border: 5px solid ;
padding: 0 30px;
border-radius: 25px;
display: inline-block;
overflow: hidden;
height: 1em;
line-height: 1em;
font-weight: bold;
font-size: 16em;
}
.box:after {
position: relative;
white-space: pre;
top:-7em; /* Here 7 */
content: "0A 1A 2A 3A 4A 5A 6A 7A 8A 9A"; /* You can have all the numbers here */
animation: animate 7s steps(8); /* Here 8 */
}
@keyframes animate {
0% {
top: 0;
}
100% {
top: -8em; /* Here 8 */
}
}
<span class="box"></span>
With some CSS variables to have something generic:
body {
background: pink;
}
.box {
color: #fff;
border: 5px solid ;
padding: 0 30px;
border-radius: 25px;
display: inline-block;
overflow: hidden;
height: 1em;
line-height: 1em;
font-weight: bold;
font-size: 16em;
}
.box:after {
position: relative;
white-space: pre;
top:calc(var(--c)*-1em);
content: "0A 1A 2A 3A 4A 5A 6A 7A 8A 9A";
animation: animate calc(var(--c)*1s) steps(calc(var(--c) + 1));
}
@keyframes animate {
0% {
top: 0;
}
100% {
top: calc(-1em*(var(--c) + 1));
}
}
<span class="box" style="--c:7"></span>
<span class="box" style="--c:5"></span>
<span class="box" style="--c:2"></span>