Вот сумасшедшая идея, основанная на уловке фона и украшении коробки. Он также может работать с любым типом шрифтов:
@font-face {
font-family: danub;
src: url(https://cdn.getforge.com/remirror.getforge.io/1585586993/danub.ttf);
}
h1 {
font-size: 3rem;
height:1.1em; /* Same a gradient height */
line-height:1.3em; /* to rectify the oveflow (bigger than the height) */
word-break: break-all; /* This is the most important trick */
overflow: hidden; /* hide the line break */
font-family: danub;
animation:typing 10s linear forwards;
}
h1 span{
/* padding same as gradient width */
padding-right:0.1em; /* width height */
background:linear-gradient(red,red) right/ 0.1em 1.1em no-repeat;
-webkit-box-decoration-break:clone;
box-decoration-break:clone;
animation:blink-caret 0.5s infinite forwards;
}
@keyframes typing {
from {
max-width: 1em;
}
to {
max-width:100%;
}
}
@keyframes blink-caret {
to {
/* we change the gradient to transparent */
background-image:linear-gradient(transparent,transparent);
}
}
<h1><span>remirror text</span></h1>
<h1 style="font-family:arial"><span>another text here</span></h1>
Чтобы уловить трюк, удалите переполнение, чтобы увидеть, как градиент ведет себя при оформлении коробки:
@font-face {
font-family: danub;
src: url(https://cdn.getforge.com/remirror.getforge.io/1585586993/danub.ttf);
}
h1 {
font-size: 3rem;
height:1.1em; /* Same a gradient height */
line-height:1.2em; /* to rectify the oveflow */
word-break: break-all; /* This is the most important trick */
font-family: danub;
animation:typing 25s linear forwards;
border:1px solid;
}
h1 span{
padding-right:0.1em; /* width height */
background:linear-gradient(red,red) right/ 0.1em 1.1em no-repeat;
-webkit-box-decoration-break:clone;
box-decoration-break:clone;
}
@keyframes typing {
from {
max-width: 1em;
}
to {
max-width:100%;
}
}
<h1><span>remirror text</span></h1>