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

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

相关推荐
掘金安东尼8 小时前
让 JavaScript 更容易「善后」的新能力
前端·javascript·面试
掘金安东尼8 小时前
用 HTMX 为 React Data Grid 加速实时更新
前端·javascript·面试
灵感__idea10 小时前
Hello 算法:众里寻她千“百度”
前端·javascript·算法
袋鼠云数栈UED团队11 小时前
基于 Lexical 实现变量输入编辑器
前端·javascript·架构
AAA阿giao12 小时前
从零构建一个现代登录页:深入解析 Tailwind CSS + Vite + Lucide React 的完整技术栈
前端·css·react.js
亦妤12 小时前
JS执行机制、作用域及作用域链
javascript
SuperEugene13 小时前
表单最佳实践:从 v-model 到自定义表单组件(含校验)
前端·javascript·vue.js
不会敲代码113 小时前
React性能优化:深入理解useMemo和useCallback
前端·javascript·react.js
YukiMori2316 小时前
一个有趣的原型继承实验:为什么“男人也会生孩子”?从对象赋值到构造函数继承的完整推演
前端·javascript
摸鱼的春哥16 小时前
惊!黑客靠AI把墨西哥政府打穿了,海量数据被黑
前端·javascript·后端