Snake border animation button html+css

effect:

Insert picture description here

Production process:

1. Define the label, the a label is the button, and the 4 spans are the blue edges of the four actions around the button. :

<a href="https://blog.csdn.net/luo1831251387?spm=1000.2115.3001.5343" class="night" target="blank">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
          night
    </a>

2. Define the basic style of button .night:

.night{
    
    
            position: relative;
            width: 300px;
            height: 100px;
            color: rgb(18, 190, 243);
            letter-spacing: 12px;
            font-size: 50px;
            line-height: 100px;
            text-align: center;
            /* background-color: rgb(31, 49, 133); */
            background-image: linear-gradient(90deg, rgb(40, 62, 161) 50%,rgb(31, 49, 133) 50% );
            text-transform: uppercase;
            user-select: none;
            text-decoration: none;
            overflow: hidden;
            box-shadow: inset 0 0 10px rgb(14, 20, 105),
            0 0 5px rgb(9, 208, 235);
            transition: all 0.5s;
            
        }

position: Relative positioning.
letter-spacing: word spacing.
linear-gradient: gradient color.
text-transform: All letters are uppercase.
user-select: The text cannot be selected.
text-decoration: Eliminate the default underline.
overflow: overflow hidden.
box-shadow: shadow.
transition: transition effect.

3. Mouse over button style changes:

 .night:hover{
    
    
            text-shadow: 0 0 5px rgb(18, 190, 243),
            0 0 8px rgb(18, 190, 243),
            0 0 10px rgb(18, 190, 243); 
            background-image: linear-gradient(90deg, rgb(25, 38, 99) 50%,rgb(13, 22, 58) 50% );
            box-shadow: inset 0 0 10px rgb(14, 20, 105),
            0 0 5px rgb(9, 208, 235),
            0 0 10px rgb(9, 208, 235);
        }

text-shadow: text shadow.
lineear-gradient: gradient color change.
box-shadow: The box shadow changes.

4. The basic style of 4 spans:

  .night span{
    
    
            position: absolute;   
        }

absolute absolute positioning

5. Set the style of the blue movement line above the button:

 .night span:nth-child(1){
    
    
            top: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background-image: linear-gradient(to right, transparent , rgb(0, 153, 255) );
            animation: move1 2s linear infinite;
        }
        @keyframes move1 {
    
    
            0%{
    
    
                transform: translateX(-100%);
            }
            100%{
    
    
                transform: translateX(100%);
            }
        }

linear-gradient: gradient color. transparent is a transparent color.
animation: Set up an animation to make the blue line move.
transform: translateX(-100%); The offset on the X axis is -100%.
transform: translateX(100%); Let it shift to 100%.

6. By analogy, the other three can also be animated, and then the left and right ones can be set to delay the animation. :

.night span:nth-child(2){
    
    
            top: 0;
            right: 0;
            width: 2px;
            height: 100%;
            transform: translateY(-100%);
            background-image: linear-gradient(to bottom,  transparent ,  rgb(0, 153, 255)  );            
            animation: move2 2s linear infinite;
            animation-delay: 1s;
        }
        @keyframes move2 {
    
    
           
            100%{
    
    
                transform: translateY(100%);
            }
        }
        .night span:nth-child(3){
    
    
            left: 0;
            bottom: 0;
            width: 100%;
            height: 2px;
            background-image: linear-gradient(to left, transparent , rgb(0, 153, 255) );
            animation: move3 2s linear infinite;
        }
        @keyframes move3 {
    
    
            0%{
    
    
                transform: translateX(100%);
            }
            100%{
    
    
                transform: translateX(-100%);
            }
        }
        .night span:nth-child(4){
    
    
            top: 0;
            left: 0;
            width: 2px;
            height: 100%;
            transform: translateY(100%);
            background-image: linear-gradient(to top, transparent , rgb(0, 153, 255) );
            animation: move4 2s linear infinite;
            animation-delay: 1s;
        }
        @keyframes move4 {
    
    
            100%{
    
    
                transform: translateY(-100%);
            }
        }

animation-delay: 1s; Set the animation delay to play for 1 second.

Complete code:

<!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>Document</title>
    
    <style>
        *{
     
     
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
     
     
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: rgb(4, 4, 19);
        }
        .night{
     
     
            position: relative;
            width: 300px;
            height: 100px;
            color: rgb(18, 190, 243);
            letter-spacing: 12px;
            font-size: 50px;
            line-height: 100px;
            text-align: center;
            /* background-color: rgb(31, 49, 133); */
            background-image: linear-gradient(90deg, rgb(40, 62, 161) 50%,rgb(31, 49, 133) 50% );
            text-transform: uppercase;
            user-select: none;
            text-decoration: none;
            overflow: hidden;
            box-shadow: inset 0 0 10px rgb(14, 20, 105),
            0 0 5px rgb(9, 208, 235);
            transition: all 0.5s;
            
        }
        .night:hover{
     
     
            text-shadow: 0 0 5px rgb(18, 190, 243),
            0 0 8px rgb(18, 190, 243),
            0 0 10px rgb(18, 190, 243); 
            background-image: linear-gradient(90deg, rgb(25, 38, 99) 50%,rgb(13, 22, 58) 50% );
            box-shadow: inset 0 0 10px rgb(14, 20, 105),
            0 0 5px rgb(9, 208, 235),
            0 0 10px rgb(9, 208, 235);
        }
            
        .night span{
     
     
            position: absolute;   
        }
        .night span:nth-child(1){
     
     
            top: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background-image: linear-gradient(to right, transparent , rgb(0, 153, 255) );
            animation: move1 2s linear infinite;
        }
        @keyframes move1 {
     
     
            0%{
     
     
                transform: translateX(-100%);
            }
            100%{
     
     
                transform: translateX(100%);
            }
        }
        .night span:nth-child(2){
     
     
            top: 0;
            right: 0;
            width: 2px;
            height: 100%;
            transform: translateY(-100%);
            background-image: linear-gradient(to bottom,  transparent ,  rgb(0, 153, 255)  );            
            animation: move2 2s linear infinite;
            animation-delay: 1s;
        }
        @keyframes move2 {
     
     
           
            100%{
     
     
                transform: translateY(100%);
            }
        }
        .night span:nth-child(3){
     
     
            left: 0;
            bottom: 0;
            width: 100%;
            height: 2px;
            background-image: linear-gradient(to left, transparent , rgb(0, 153, 255) );
            animation: move3 2s linear infinite;
        }
        @keyframes move3 {
     
     
            0%{
     
     
                transform: translateX(100%);
            }
            100%{
     
     
                transform: translateX(-100%);
            }
        }
        .night span:nth-child(4){
     
     
            top: 0;
            left: 0;
            width: 2px;
            height: 100%;
            transform: translateY(100%);
            background-image: linear-gradient(to top, transparent , rgb(0, 153, 255) );
            animation: move4 2s linear infinite;
            animation-delay: 1s;
        }
        @keyframes move4 {
     
     
            100%{
     
     
                transform: translateY(-100%);
            }
        }
    </style>
</head>
<body>
    <a href="https://blog.csdn.net/luo1831251387?spm=1000.2115.3001.5343" class="night" target="blank">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
          night
    </a>
</body>
</html>

to sum up:

If you think it’s good, just like it~ I
forgot to say it. After
a meal, I finally passed the third class~

Other articles:
Colorful streamer text html+css
bubble floating background special effect html+css
simple clock special effect html+css+js
cyberpunk style button html+css
imitating NetEase cloud official website carousel image html+css+js
water wave loading animation html+ css
navigation bar scrolling gradient effect html+css+js
book page turning html+css
3D stereo album html+css
neon drawing board effect html+css+js
remember some CSS attribute summary (1)
Sass summary notes
... etc.

Guess you like

Origin blog.csdn.net/luo1831251387/article/details/115058088