HTML&CSS:必学!跳跃的动态标题

这段代码实现了一个动态的标题效果,其中每个字母依次跳动,营造出一种活泼的视觉效果。


大家复制代码时,可能会因格式转换出现错乱,导致样式失效。建议先少量复制代码进行测试,若未能解决问题,私信回复源码两字,我会发送完整的压缩包给你。

演示效果

HTML&CSS

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公众号关注:前端Hardy</title>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            background: #FF7777;
            -webkit-font-smoothing: antialiased;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        h1 {
            height: 100px;
        }

        h1 span {
            position: relative;
            top: 20px;
            display: inline-block;
            animation: bounce .3s ease infinite alternate;
            font-family: none;
            font-size: 80px;
            color: #FFF;
            text-shadow: 0 1px 0 #CCC,
                0 2px 0 #CCC,
                0 3px 0 #CCC,
                0 4px 0 #CCC,
                0 5px 0 #CCC,
                0 6px 0 transparent,
                0 7px 0 transparent,
                0 8px 0 transparent,
                0 9px 0 transparent,
                0 10px 10px rgba(0, 0, 0, .4);
        }

        h1 span:nth-child(2) {
            animation-delay: .1s;
        }

        h1 span:nth-child(3) {
            animation-delay: .2s;
        }

        h1 span:nth-child(4) {
            animation-delay: .3s;
        }

        h1 span:nth-child(5) {
            animation-delay: .4s;
        }

        h1 span:nth-child(6) {
            animation-delay: .5s;
        }

        h1 span:nth-child(7) {
            animation-delay: .6s;
        }

        h1 span:nth-child(8) {
            animation-delay: .7s;
        }

        @keyframes bounce {
            100% {
                top: -20px;
                text-shadow: 0 1px 0 #CCC,
                    0 2px 0 #CCC,
                    0 3px 0 #CCC,
                    0 4px 0 #CCC,
                    0 5px 0 #CCC,
                    0 6px 0 #CCC,
                    0 7px 0 #CCC,
                    0 8px 0 #CCC,
                    0 9px 0 #CCC,
                    0 50px 25px rgba(0, 0, 0, .2);
            }
        }
    </style>
</head>

<body>
    <h1>
        <span>I</span>
        <span>L</span>
        <span>O</span>
        <span>V</span>
        <span>E</span>
        <span>Y</span>
        <span>O</span>
        <span>U</span>
    </h1>
</body>

</html>

HTML 结构

  • h1:定义标题,包含多个span元素,每个span包含一个字母。
  • span:定义标题中的每个字母,通过CSS实现动态效果。

CSS 样式

  • html, body:设置页面的整体布局,背景颜色为#FF7777,并使用flex布局居中对齐内容。
  • h1:定义标题的样式,设置高度为100px。
  • h1 span:定义标题中每个字母的样式,包括相对定位、内联块显示、动画效果、字体大小、颜色和文本阴影。
  • h1 span:nth-child(2):定义第二个字母的动画延迟为.1s。
  • h1 span:nth-child(3):定义第三个字母的动画延迟为.2s。
  • h1 span:nth-child(4):定义第四个字母的动画延迟为.3s。
  • h1 span:nth-child(5):定义第五个字母的动画延迟为.4s。
  • h1 span:nth-child(6):定义第六个字母的动画延迟为.5s。
  • h1 span:nth-child(7):定义第七个字母的动画延迟为.6s。
  • h1 span:nth-child(8):定义第八个字母的动画延迟为.7s。
  • @keyframes bounce:定义跳动动画,通过改变top和text-shadow属性实现字母的上下跳动效果。

各位互联网搭子,要是这篇文章成功引起了你的注意,别犹豫,关注、点赞、评论、分享走一波,让我们把这份默契延续下去,一起在知识的海洋里乘风破浪!

相关推荐
云浪11 小时前
Go 并发实战:从零实现一个高并发安全的任务调度器
javascript·后端·go
OpsEye19 小时前
大模型账单对账难:不同厂商 Token 统计口径差异怎么处理
javascript·ai编程
全栈项目管理程序猿19 小时前
ArcGIS JS 基础教程(32):体元系列 - VoxelSlice 体元切片
前端·javascript
Hilaku21 小时前
AI 流式输出都用 SSE,什么时候必须换 WebSocket?
前端·javascript·程序员
奇牙coding21 小时前
Codex CLI 升级后多文件编辑静默失效:config.yaml 枚举变更排查与修复指南
java·前端·javascript·ai
java1234_小锋1 天前
【技术专题】HTML5 网页技术 - HTML5 表单基础以及增强
前端·html·html5
燕落南枝1 天前
HTML 学习:辅助标签 label 与字符实体
前端·学习·html
不简说1 天前
AI 帮你画模板、点一下就云打印:sv-print 这三个月都干了啥
前端·javascript·人工智能
大明二代1 天前
从零构建 Mastra RAG MVP:DeepSeek、SiliconFlow 与 PostgreSQL/pgvector 实战
javascript·数据库·人工智能
结局无敌1 天前
React Native for OpenHarmony 实战:三方库 react-native-paper 的鸿蒙化适配指南
javascript·人工智能·深度学习·react native·react.js·ecmascript·harmonyos