<style>
* {
margin: 0;
padding: 0;
}
@keyframes cursors {
0% {
border-left-color: rgba(0, 0, 0, 0);
}
50% {
border-left-color: rgba(0, 0, 0, 1);
}
0% {
border-left-color: rgba(0, 0, 0, 0);
}
}
@keyframes cover {
from {
left: 0;
}
to {
left: 100%;
}
}
.wrapper {
height: 100px;
/* 该字体是等距,所以不用自己设置等距的字体 */
font-family: monospace;
font-size: 40px;
line-height: 100px;
display: inline-block;
position: relative;
}
.wrapper::after {
content: "";
position: absolute;
width: 100%;
height: 90px;
top: 10px;
background-color: #fff;
border-left: 2px solid #000;
box-sizing: border-box;
animation: cursors 1s steps(1, end) forwards infinite,
/* 关键在与这个动画,每一步实现的是一个字 */
cover 12s steps(12, end);
}
</style>