点击查看html编辑器说明文档

纯CSS实现文字输入动画效果edit icon

|
|
Fork(复制)
|
|
提交反馈
嵌入
设置
下载
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ...
展开
</head>
<body>
<h1>Pure CSS Typing Text Demo.</h1>
<em>此 Demo 仅支持英文</em>
</body>
CSS
格式化
body {
    background: #282828;
    color: #fff;
    height: 100vh;
    display:flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

h1 {
    font: bold 190% Consolas, Monaco, monospace;
    border-right: 0.1em solid;
    width: 16.5em;
    width: 26ch;
    white-space: nowrap;
    overflow: hidden;
    animation: typing 3s steps(26, end) ,
        cursor-blink 0.4s step-end infinite alternate;
}

/* 通过控制文本展示宽度来模拟输入效果 */
@keyframes typing {
    from {
        width: 0;
    }
}

/* 模拟光标闪烁 */
@keyframes cursor-blink {
    50% {
        border-color: transparent;
    }
}
JS
格式化
预览
控制台