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>
相关推荐
小帅不太帅10 分钟前
我随手发了几张截图,白拿了一个月 AI 顶配会员
前端·github
36岁的我开始学习打篮球11 分钟前
外规内化技术架构
前端
雪隐27 分钟前
用Flutter做背单词APP-03为了给单词库塞满数据,我让AI给我打了上万份工
前端·人工智能·后端
hunterandroid28 分钟前
Android 安全最佳实践:从数据存储到网络通信的防护思路
前端
H Journey28 分钟前
web开发学习:html、css、js
前端·css·html·js
hunterandroid34 分钟前
Compose 性能优化:从卡顿到丝滑的实战经验
前端
hunterandroid38 分钟前
Kotlin Coroutines 在 Android 项目中的落地实战
前端
不一样的少年_1 小时前
不用框架,手搓 AI Agent:(一) 先让它跑起来
前端·后端·agent
味悲1 小时前
浏览器解析机制与XSS的15种编码绕过
前端·xss
小牛itbull1 小时前
【译】为什么我使用 React 重构了 WordPress?
前端·react.js·重构