发布时间:2023-04-21 文章分类:WEB开发, 电脑百科 投稿人:王小丽 字号: 默认 | | 超大 打印

文章目录

    • 前言
    • 效果图
    • HTML篇
    • CSS篇
      • 1. 盒子模型设置
      • 2. 动画设置
    • 完整代码

前言

我是前端小刘不怕牛牛,love you 3000,愿你能遇到值得的人。
今天分享一个唯美的文字闪烁CSS特效
希望大家能喜欢

效果图

每天一个CSS小特效,文字闪烁——【钢铁侠:爱你三千遍】


HTML篇

代码:

<div class="main">
        <div>
            <span>I</span></div>
        <div>
            <span>l</span>
            <span>o</span>
            <span>v</span>
            <span>e</span></div>
        <div>
            <span>y</span>
            <span>o</span>
            <span>u</span></div>
        <div>
            <span>3</span>
            <span>0</span>
            <span>0</span>
            <span>0</span></div>
</div>

CSS篇

1. 盒子模型设置

代码如下:

        body{
            background-color: black;
        }
        .main{
            padding-top: 249px;
            margin: 0 auto;
            width: 1200px;
            display: flex;
            justify-content: space-around;
            font-family: 'Courier New', Courier, monospace;
        }
        .main div{
            display: inline-block;
            color: transparent;
        }
        span{
            font-size: 120px;
            animation: twinkle 4.6s linear infinite;
        }

2. 动画设置

代码如下:

 .main div:nth-child(1) span:nth-child(1){
            animation-delay: 0s;
        }
        .main div:nth-child(2) span:nth-child(1){
            animation-delay: 0.4s;
        }
        .main div:nth-child(2) span:nth-child(2){
            animation-delay: 0.8s;
        }
        .main div:nth-child(2) span:nth-child(3){
            animation-delay: 1.2s;
        }
        .main div:nth-child(2) span:nth-child(4){
            animation-delay: 1.6s;
        }
        .main div:nth-child(3) span:nth-child(1){
            animation-delay: 2.0s;
        }
        .main div:nth-child(3) span:nth-child(2){
            animation-delay: 2.4s;
        }
        .main div:nth-child(3) span:nth-child(3){
            animation-delay: 2.8s;
        }
        .main div:nth-child(4) span:nth-child(1){
            animation-delay: 3.2s;
        }
        .main div:nth-child(4) span:nth-child(2){
            animation-delay: 3.6s;
        }
        .main div:nth-child(4) span:nth-child(3){
            animation-delay: 4s;
        }
        .main div:nth-child(4) span:nth-child(4){
            animation-delay: 4.4s;
        }
        @keyframes twinkle{
            0%{
                color: transparent;
            } 
            100%{
                color: aliceblue;
                text-shadow: 0 0 4px skyblue,
                                0 0 10px skyblue,
                                0 0 20px skyblue,
                                0 0 30px skyblue,
                                0 0 40px skyblue,
                                0 0 50px skyblue,
                                0 0 60px skyblue,
                                0 0 70px skyblue,
                                0 0 80px skyblue,
                                0 0 90px skyblue,
                                0 0 100px skyblue,
                                0 0 110px skyblue,
                                0 0 120px skyblue,
                                0 0 130px skyblue;
                /* 文字阴影叠加 */
            }
        }

(随便叠了一个)
每天一个CSS小特效,文字闪烁——【钢铁侠:爱你三千遍】

完整代码

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文字闪烁效果</title>
    <style>
        body{
            background-color: black;
        }
        .main{
            padding-top: 249px;
            margin: 0 auto;
            width: 1200px;
            display: flex;
            justify-content: space-around;
            font-family: 'Courier New', Courier, monospace;
        }
        .main div{
            display: inline-block;
            color: transparent;
        }
        span{
            font-size: 120px;
            animation: twinkle 4.6s linear infinite;
        }
        .main div:nth-child(1) span:nth-child(1){
            animation-delay: 0s;
        }
        .main div:nth-child(2) span:nth-child(1){
            animation-delay: 0.4s;
        }
        .main div:nth-child(2) span:nth-child(2){
            animation-delay: 0.8s;
        }
        .main div:nth-child(2) span:nth-child(3){
            animation-delay: 1.2s;
        }
        .main div:nth-child(2) span:nth-child(4){
            animation-delay: 1.6s;
        }
        .main div:nth-child(3) span:nth-child(1){
            animation-delay: 2.0s;
        }
        .main div:nth-child(3) span:nth-child(2){
            animation-delay: 2.4s;
        }
        .main div:nth-child(3) span:nth-child(3){
            animation-delay: 2.8s;
        }
        .main div:nth-child(4) span:nth-child(1){
            animation-delay: 3.2s;
        }
        .main div:nth-child(4) span:nth-child(2){
            animation-delay: 3.6s;
        }
        .main div:nth-child(4) span:nth-child(3){
            animation-delay: 4s;
        }
        .main div:nth-child(4) span:nth-child(4){
            animation-delay: 4.4s;
        }
        @keyframes twinkle{
            0%{
                color: transparent;
            } 
            100%{
                color: aliceblue;
                text-shadow: 0 0 4px skyblue,
                                0 0 10px skyblue,
                                0 0 20px skyblue,
                                0 0 30px skyblue,
                                0 0 40px skyblue,
                                0 0 50px skyblue,
                                0 0 60px skyblue,
                                0 0 70px skyblue,
                                0 0 80px skyblue,
                                0 0 90px skyblue,
                                0 0 100px skyblue,
                                0 0 110px skyblue,
                                0 0 120px skyblue,
                                0 0 130px skyblue;
                /* 文字阴影叠加 */
                /* text-shadow: 0 0 4px red,
                                0 0 10px orange,
                                0 0 20px yellow,
                                0 0 30px green,
                                0 0 40px blue,
                                0 0 50px skyblue,
                                0 0 60px blueviolet; */
            }
        }
    </style>
</head>
<body>
    <div class="main">
        <div>
            <span>I</span></div>
        <div>
            <span>l</span>
            <span>o</span>
            <span>v</span>
            <span>e</span></div>
        <div>
            <span>y</span>
            <span>o</span>
            <span>u</span></div>
        <div>
            <span>3</span>
            <span>0</span>
            <span>0</span>
            <span>0</span></div>
    </div>
</body>
</html>

这里牛牛推荐一个功能强大的刷题软件,牛客网。里面有各大厂的面试题,还有模拟面试,让你身临其境感受面试,不仅如此,还要很多大佬的面试经验,看完硕果累累。甚至可以在里面投递简历,🍓🍓感兴趣的点此进入牛客网

今天的小案例到这就结束啦,如果觉得好玩有帮助的可以用小手点个攒关注下吗,牛牛后面会陆续更新好玩的CSS特效,还有JS的页面效果实现🤗🤗🤗