css实现文字打字机效果


html

typescript 复制代码
<body>
    <p class="line animation">
        我和我的祖国,一刻也不能分割
    </p>
</body>

css

typescript 复制代码
 <style type="text/css">
        html,
        body {
            height: 100%;
        }

        body {
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            /* background: #222; */
        }

        .line {
            width: 674px;
            border-right: 2px solid #eee;
            font-size: 28px;
            text-align: center;
            white-space: nowrap;
            overflow: hidden;
            color: #5ec4ff;
            background: linear-gradient(0deg, #5ec4ff 0%, #ffffff 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .animation {
            animation: grow 4s steps(44) 1s normal both,
                blink 0.5s steps(44) infinite normal;
        }

        @keyframes grow {
            from {
                width: 0;
            }

            to {
                width: 400px;
            }
        }

        @keyframes blink {
            from {
                border-right-color: #eee;
            }

            to {
                border-right-color: #222;
            }
        }
    </style>
相关推荐
爱勇宝6 分钟前
初创公司的“自己人”,到底能当多久?
前端·后端·程序员
晴天1612 分钟前
前端模块化规范全景解析:CommonJS、AMD、ESM、UMD
前端
三十而立洋1 小时前
深入理解 npm:从核心机制到常用命令全解析
前端·前端工程化
Canace1 小时前
最新版 Codex 工作流的问题
前端·人工智能·agent
变与不变8061 小时前
引用类型、内存原理与对象
开发语言·前端·javascript
jearry1 小时前
给 C++ 老程序补现代 UI:WebView2 多入口资源加载与虚拟主机名实践
前端
打呵欠的猫1 小时前
让 AI 帮你写 Git Commit Message:从"fix bug"到语义化提交只需一个 Hook
前端·ai编程
labixiong1 小时前
CSS 锚点定位实测:零 JS 实现气泡跟随,自动翻转很香但暗藏 3 个致命坑
前端·css
qibmz1 小时前
用 DeepSeek 给 GitHub 仓库加 PR 自动 Review
前端
计算机魔术师1 小时前
幻觉率从 4.2% 降到 2% 又退回,GPT-6 Astra 到底在藏什么
前端