【css酷炫效果】纯CSS实现文字逐字显现打字效果

想直接拿走的老板,链接放在这里:https://download.youkuaiyun.com/download/u011561335/90490479

创作随缘,不定时更新。

创作背景

刚看到csdn出活动了,赶时间,直接上代码。

html结构

<div class="typewriter">
    <p class="typing-text">Welcome to CSS Magic!</p>
</div>

css样式

.typewriter {
    width: fit-content;
}

.typing-text {
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #333; /* 光标模拟 */
    font-family: 'Courier New', monospace; /* 等宽字体 */
    animation: typing 3s steps(16) forwards,
               cursor-blink 0.8s step-end infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 16ch; } /* 字符数(ch单位) */
}

@keyframes cursor-blink {
    from, to { border-color: transparent; }
    50% { border-color: #333; }
}

完整代码

基础版

<!DOCTYPE html>
<html>
<head>
<style>
.typewriter {
    width: fit-content;
}

.typing-text {
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #333; /* 光标模拟 */
    font-family: 'Courier New', monospace; /* 等宽字体 */
    animation: typing 3s steps(16) forwards,
               cursor-blink 0.8s step-end infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 16ch; } /* 字符数(ch单位) */
}

@keyframes cursor-blink {
    from, to { border-color: transparent; }
    50% { border-color: #333; }
}
</style>
</head>
<body>
    <div style='text-align:center;margin-top:50px;'>
		<div class="typewriter">
			<p class="typing-text">Welcome to CSS Magic!</p>
		</div>
	</div>
	
</body>
</html>

进阶版(彩色光标)

<!DOCTYPE html>
<html>
<head>
<style>
.typewriter {
    width: fit-content;
}

.typing-text {
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #333; /* 光标模拟 */
    font-family: 'Courier New', monospace; /* 等宽字体 */
    animation: typing 3s steps(16) forwards,
               cursor-blink 0.8s step-end infinite;
    border-image: linear-gradient(45deg, #ff6b6b, #4ecdc4) 1;
    border-width: 3px;
}

@keyframes typing {
    from { width: 0; }
    to { width: 16ch; } /* 字符数(ch单位) */
}

@keyframes cursor-blink {
    from, to { border-color: transparent; }
    50% { border-color: #333; }
}

</style>
</head>
<body>
    <div style='text-align:center;margin-top:50px;'>
		<div class="typewriter">
			<p class="typing-text">Welcome to CSS Magic!</p>
		</div>
	</div>
	
</body>
</html>

进阶版2(彩色多行打印)

<!DOCTYPE html>
<html>
<head>
<style>
.typewriter {
    width: fit-content;
}

.typing-text {
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #333; /* 光标模拟 */
    font-family: 'Courier New', monospace; /* 等宽字体 */
    animation: typing 3s steps(16) forwards,
               cursor-blink 0.8s step-end infinite;
    border-image: linear-gradient(45deg, #ff6b6b, #4ecdc4) 1;
    border-width: 3px;
    height: 1.2em; /* 单行高度 */
    animation: 
        typing 4s steps(40),
        line-change 0.5s step-end 2,
        cursor-blink 0.8s infinite;
}

@keyframes line-change {
    0% { height: 1.2em; }
    100% { height: 3.4em; }
}
@keyframes typing {
    from { width: 0; }
    to { width: 16ch; } /* 字符数(ch单位) */
}

@keyframes cursor-blink {
    from, to { border-color: transparent; }
    50% { border-color: #333; }
}

</style>
</head>
<body>
    <div style='text-align:center;margin-top:50px;'>
		<div class="typewriter">
			<p class="typing-text">Welcome to CSS Magic!</p>
			<p class="typing-text">Welcome to CSS Magic!</p>
		</div>
	</div>
	
</body>
</html>

效果图

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰夏之夜影

赠人玫瑰,手留余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值