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

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

相关推荐
开开心心就好10 小时前
批量提取PDF中的图片,直接导出原图
前端·javascript·支持向量机·智能手机·pdf·html·启发式算法
默_笙14 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan15 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
天若有情67317 小时前
【纯前端小工具】公历生日转农历,批量查询每年农历生日对应的公历日期(GitHub Pages在线直接用)
前端·javascript·github pages·农历转换·lunisolar·网页小工具
林语琛18 小时前
我写的 switch…break 被 Babel 偷偷吞了
前端·javascript·babel
liuchangng18 小时前
Jev 模型研究:从生成式大模型到决策式模型——System One、RLCD 校准与采用边界
java·javascript·人工智能·python·深度学习
扶苏100219 小时前
CSS 图标换色指南:用 brightness / invert / mask 把任意图片改成想要的颜色
css
我命由我1234520 小时前
CSS - CSS 媒体查询 orientation
前端·javascript·css·html·css3·html5·js
志尊宝1 天前
Vue3 零基础每日笔记(048):嵌套路由与命名视图——后台管理系统布局雏形
前端·javascript·vue.js·笔记·html5
@tangguo1231 天前
npm 和 yarn 配置说明
前端·javascript·npm·node.js·yarn