文字点闪特效 html+css

上效果先:

北极光之夜

先言:

这是在网上看到的效果,觉得挺有趣,所以我也弄了一个然后写篇文章记录。

实现:

1.定义html标签:

 <h1>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </h1>

2.文字的基本样式,大小颜色等:

 h1{
            font-family: 'fangsong';
            font-size: 6em;
            color: rgba(19, 18, 18, 0.8);
        }
        span{
           display: table-cell;
           animation: san 1.5s linear infinite;
        }

display: table-cell;此元素会作为一个表格单元格显示(类似 和 )

3.文字发亮的效果,就闪一下然后就又会(5%-95%的时候)变暗:

 @keyframes san{
            0%{
                color: rgb(255, 255, 255);            
                text-shadow: 0 0 5px rgb(1, 210, 247),
                            0 0 15px rgb(1, 210, 247),
                            0 0 25px rgb(1, 210, 247),
                            0 0 50px rgb(1, 210, 247),
                            0 0 80px rgb(1, 210, 247),
                            0 0 120px rgb(1, 210, 247),
                            0 0 160px rgb(1, 210, 247),
                            0 0 200px rgb(1, 210, 247);
            }
            5%,95%{
                color: rgba(19, 18, 18, 0.8);
               text-shadow: none;
            }
            100%{
               color: rgb(255, 255, 255);           
               text-shadow: 0 0 5px rgb(1, 210, 247),
                            0 0 15px rgb(1, 210, 247),
                            0 0 25px rgb(1, 210, 247),
                            0 0 50px rgb(1, 210, 247),
                            0 0 80px rgb(1, 210, 247),
                            0 0 120px rgb(1, 210, 247),
                            0 0 160px rgb(1, 210, 247),
                            0 0 200px rgb(1, 210, 247);
            }
        }

text-shadow:是给它加阴影,写了很多行是为了阴影更亮;

4.制造时间差,让不同的时间不同的文字亮;

 h1 span:nth-child(1){
            animation-delay:0s;
        }
        h1 span:nth-child(2){
            animation-delay:0.3s;
        } 
        h1 span:nth-child(3){
            animation-delay:0.6s;
        }
        h1 span:nth-child(4){
            animation-delay:0.9s;
        }
        h1 span:nth-child(5){
            animation-delay:1.2s;
        }

animation-delay 等待多少秒,然后才开始动画;

完整代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: rgb(0, 0, 0);
        }
        h1{
            font-family: 'fangsong';
            font-size: 6em;
            color: rgba(19, 18, 18, 0.8);
        }
        span{
           display: table-cell;
           animation: san 1.5s linear infinite;
        }
        h1 span:nth-child(1){
            animation-delay:0s;
        }
        h1 span:nth-child(2){
            animation-delay:0.3s;
        } 
        h1 span:nth-child(3){
            animation-delay:0.6s;
        }
        h1 span:nth-child(4){
            animation-delay:0.9s;
        }
        h1 span:nth-child(5){
            animation-delay:1.2s;
        }
      
        @keyframes san{
            0%{
                color: rgb(255, 255, 255);            
                text-shadow: 0 0 5px rgb(1, 210, 247),
                            0 0 15px rgb(1, 210, 247),
                            0 0 25px rgb(1, 210, 247),
                            0 0 50px rgb(1, 210, 247),
                            0 0 80px rgb(1, 210, 247),
                            0 0 120px rgb(1, 210, 247),
                            0 0 160px rgb(1, 210, 247),
                            0 0 200px rgb(1, 210, 247);
            }
            5%,95%{
                color: rgba(19, 18, 18, 0.8);
               text-shadow: none;
            }
            100%{
               color: rgb(255, 255, 255);           
               text-shadow: 0 0 5px rgb(1, 210, 247),
                            0 0 15px rgb(1, 210, 247),
                            0 0 25px rgb(1, 210, 247),
                            0 0 50px rgb(1, 210, 247),
                            0 0 80px rgb(1, 210, 247),
                            0 0 120px rgb(1, 210, 247),
                            0 0 160px rgb(1, 210, 247),
                            0 0 200px rgb(1, 210, 247);
            }
        }
    </style>
</head>
<body>
    <h1>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </h1>
</body>
</html>

总结:

每天都对自己说:

生活不止眼前的苟且

还有诗和远方的田野

你赤手空拳来到人世间

为找到那片海不顾一切~
在这里插入图片描述

  • 34
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北极光之夜。

谢谢~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值