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属性实现字母的上下跳动效果。

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

相关推荐
起床学FPGA2 小时前
AI回答问题之后,会自动跳到最下面的问题
开发语言·javascript·ecmascript
默_笙5 小时前
❗ 点击计数按钮,为什么"峨眉队"也跟着重新渲染?React.memo 说:我记住了
前端·javascript
名字还没想好☜5 小时前
Next.js 用 Server Components 直连数据库:去掉 API 层的边界,和三条别踩的安全红线
前端·javascript·数据库·安全·react·next.js
Brown.alexis7 小时前
es6知识点5-自备使用
前端·javascript·es6
杨利杰YJlio7 小时前
KB5121003更新详解:安全启动证书、AI组件、资源管理器与安装验证
前端·javascript·后端
3秒一个大8 小时前
JS 数组去重全方案:从基础到通用万能去重函数
前端·javascript
可视之道8 小时前
CSS Container Queries 在组态大屏中的实战
css
晴天168 小时前
Electron面试题-Day19
java·javascript·electron
Hilaku9 小时前
为什么跳槽涨薪 30% 的时代彻底结束了?聊聊 2026 前端薪资的天花板
前端·javascript·程序员
大家的林语冰10 小时前
✌️ 让 Rust 再次伟大,pnpm 12 抛弃 TypeScript,移植 Rust 原地起飞!
前端·javascript·node.js