当前位置: 首页 > news >正文

【css酷炫效果】纯CSS实现故障文字特效

【css酷炫效果】纯CSS实现故障文字特效

  • 创作背景
  • html结构
  • css样式
  • 完整代码
    • 基础版
    • 进阶版(3D效果)
  • 效果图

想直接拿走的老板,链接放在这里:https://download.csdn.net/download/u011561335/90492053

创作随缘,不定时更新。

创作背景

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

html结构

<h1 class="glitch-text" data-text="ERROR 404">ERROR 404</h1>

css样式

.glitch-text {
  font-size: 5rem;
  font-weight: 900;
  position: relative;
  color: #fff;
  text-transform: uppercase;
  animation: glitch 1s infinite steps(3);
}

/* 主文字层 */
.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* 红色偏移层 */
.glitch-text::before {
  left: 2px;
  text-shadow: 
    0.05em 0 0 #ff0055,

    -0.05em -0.05em 0 #00aaff;
  animation: glitch-before 0.6s infinite steps(2);
}

/* 蓝色偏移层 */
.glitch-text::after {
  left: -2px;
  text-shadow: 

    -0.05em 0 0 #00aaff,
    0.05em 0.05em 0 #00ff99;
  animation: glitch-after 0.8s infinite steps(4);
}

@keyframes glitch {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(2px, -2px); }
  100% { transform: translate(0); }
}

@keyframes glitch-before {
  0% { clip-path: inset(20% 0 30% 0); }
  100% { clip-path: inset(10% 0 40% 0); }
}

@keyframes glitch-after {
  0% { clip-path: inset(40% 0 10% 0); }
  100% { clip-path: inset(30% 0 20% 0); }
}

完整代码

基础版

<!DOCTYPE html>
<html lang="en"> 
<head>

<title>页面特效</title>
<style type="text/css">
.glitch-text {
  font-size: 5rem;
  font-weight: 900;
  position: relative;
  color: #fff;
  text-transform: uppercase;
  animation: glitch 1s infinite steps(3);
}

/* 主文字层 */
.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* 红色偏移层 */
.glitch-text::before {
  left: 2px;
  text-shadow: 
    0.05em 0 0 #ff0055,

    -0.05em -0.05em 0 #00aaff;
  animation: glitch-before 0.6s infinite steps(2);
}

/* 蓝色偏移层 */
.glitch-text::after {
  left: -2px;
  text-shadow: 

    -0.05em 0 0 #00aaff,
    0.05em 0.05em 0 #00ff99;
  animation: glitch-after 0.8s infinite steps(4);
}

@keyframes glitch {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(2px, -2px); }
  100% { transform: translate(0); }
}

@keyframes glitch-before {
  0% { clip-path: inset(20% 0 30% 0); }
  100% { clip-path: inset(10% 0 40% 0); }
}

@keyframes glitch-after {
  0% { clip-path: inset(40% 0 10% 0); }
  100% { clip-path: inset(30% 0 20% 0); }
}
</style>

</head>
<body>

	<h1 class="glitch-text" data-text="ERROR 404">ERROR 404</h1>

</body>
</html>

进阶版(3D效果)

<!DOCTYPE html>
<html lang="en"> 
<head>

<title>页面特效</title>
<style type="text/css">
.glitch-text {
  left: 200px;
  font-size: 5rem;
  font-weight: 900;
  position: relative;
  color: #fff;
  text-transform: uppercase;
  animation: glitch 1s infinite steps(3);
}

/* 主文字层 */
.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* 红色偏移层 */
.glitch-text::before {
  left: 2px;
  text-shadow: 
    0.05em 0 0 #ff0055,

    -0.05em -0.05em 0 #00aaff;
  animation: glitch-before 0.6s infinite steps(2);
}

/* 蓝色偏移层 */
.glitch-text::after {
  left: -2px;
  text-shadow: 

    -0.05em 0 0 #00aaff,
    0.05em 0.05em 0 #00ff99;
  animation: glitch-after 0.8s infinite steps(4);
}

@keyframes glitch {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(2px, -2px); }
  100% { transform: translate(0); }
}

@keyframes glitch-before {
  0% { clip-path: inset(20% 0 30% 0); }
  100% { clip-path: inset(10% 0 40% 0); }
}

@keyframes glitch-after {
  0% { clip-path: inset(40% 0 10% 0); }
  100% { clip-path: inset(30% 0 20% 0); }
}

.glitch-text {
  transform: perspective(500px);
  animation: 
    glitch 1s infinite steps(3),
    rotate 5s linear infinite;
}

@keyframes rotate {
  25% { transform: perspective(500px) rotateY(5deg); }
  75% { transform: perspective(500px) rotateY(-5deg); }
}


</style>

</head>
<body>

	<h1 class="glitch-text" data-text="ERROR 404">ERROR 404</h1>

</body>
</html>

效果图

在这里插入图片描述

相关文章:

  • 设计模式(创建型)-单例模式
  • 【前端面试题】闭包和其应用
  • 安卓apk加固后,Android11+无法安装
  • 在NET6项目中报错,未能在命名空间System.Data.SqlClient中找到类型名SqlCommand,解决办法
  • 一次由IDEA配置引发的Redis连接问题
  • 区块链赋能:用Python开发去中心化投票系统
  • 清晰易懂的Node.js安装教程
  • 五种方案实现双链路可靠数据传输
  • IntelliJ IDEA 调试技巧指南
  • LLM系列笔记之微调数据集格式
  • 网络编程---创建客户端和服务端以及协议包
  • 开源免费一句话生成儿童故事视频核心思想解析
  • Java基础语法练习42(基本绘图-基本的事件处理机制-小坦克的绘制-键盘控制坦克移动)
  • leetcode-47.全排列II
  • 深度学习之防止过拟合
  • 【华三】路由器交换机忘记登入密码或super密码的重启操作
  • 打乱一维数组中的元素,并按照4个一组的方式添加到二维数组中
  • Python基础入门掌握(十五)
  • 删除 Git 历史提交记录中的大文件
  • 大数据学习(71)-三范式构成
  • 中国武术协会原主席张耀庭逝世,曾促成电影《少林寺》拍摄
  • 陕西省副省长窦敬丽已任宁夏回族自治区党委常委、统战部部长
  • 特朗普执政百日集会吹嘘政绩,美国消费者信心指数跌至疫情以来最低
  • 零食连锁鸣鸣很忙递表港交所:去年营收393亿元,门店超1.4万家,净利润率2.1%
  • “人工智能是年轻的事业,也是年轻人的事业”,沪上高校师生畅谈感想
  • 直播电商行业代表呼吁:携手并肩伸出援手助力外贸企业攻坚克难