I have recently been following the CSS Animation Effects Tutorial series on YouTube, which introduces many interesting CSS animation effects. The first one is a very cool neon light effect. Here I will make a simple record and share the implementation idea. This is the effect to be achieved: You can see that when the mouse moves into the button, a neon light-like effect will be produced; when the mouse moves out of the button, a beam of light will move along a fixed trajectory (around the button). Neon light realizationThe implementation of neon light is relatively simple, and can be done using multiple shadows. We add three layers of shadows to the button, and the blur radius of each layer of shadow increases from the inside to the outside. When multiple shadows are superimposed together, an effect similar to neon light can be formed. The code for this section is as follows: HTML: <div class="light"> Neon Button </div> CSS: body { background: #050901; } .light { width: fit-content; padding: 25px 30px; color: #03e9f4; font-size: 24px; text-transform:uppercase; transition: 0.5s; letter-spacing: 4px; cursor: pointer; } .light:hover { background-color: #03e9f4; color: #050801; box-shadow: 0 0 5px #03e9f4, 0 0 25px #03e9f4, 0 0 50px #03e9f4, 0 0 200px #03e9f4; } The final effect is as follows: Implementation of Moving BeamsAlthough it appears that only one beam is moving along the edge of the button, this is actually the superposition of four beams moving in different directions. Their directions of movement are: from left to right, from top to bottom, from right to left, and from bottom to top, as shown in the following figure: During this process, the light beams intersect with each other. If you only look at the edge of the button, it looks like only one light beam is moving in a clockwise direction.
The code is as follows: HTML: <div class="light"> <div></div> <div></div> <div></div> <div></div> Neon Button </div> CSS: .light { position: relative; padding: 25px 30px; color: #03e9f4; font-size: 24px; text-transform:uppercase; transition: 0.5s; letter-spacing: 4px; cursor: pointer; overflow: hidden; } .light:hover { background-color: #03e9f4; color: #050801; box-shadow: 0 0 5px #03e9f4, 0 0 25px #03e9f4, 0 0 50px #03e9f4, 0 0 200px #03e9f4; } .light div { position: absolute; } .light div:nth-child(1){ width: 100%; height: 2px; top: 0; left: -100%; background: linear-gradient(to right,transparent,#03e9f4); animation: animate1 1s linear infinite; } .light div:nth-child(2){ width: 2px; height: 100%; top: -100%; right: 0; background: linear-gradient(to bottom,transparent,#03e9f4); animation: animate2 1s linear infinite; animation-delay: 0.25s; } .light div:nth-child(3){ width: 100%; height: 2px; bottom: 0; right: -100%; background: linear-gradient(to left,transparent,#03e9f4); animation: animate3 1s linear infinite; animation-delay: 0.5s; } .light div:nth-child(4){ width: 2px; height: 100%; bottom: -100%; left: 0; background: linear-gradient(to top,transparent,#03e9f4); animation: animate4 1s linear infinite; animation-delay: 0.75s; } @keyframes animate1 { 0% { left: -100%; } 50%,100% { left: 100%; } } @keyframes animate2 { 0% { top: -100%; } 50%,100% { top: 100%; } } @keyframes animate3 { 0% { right: -100%; } 50%,100% { right: 100%; } } @keyframes animate4 { 0% { bottom: -100%; } 50%,100% { bottom: 100%; } } This will achieve the effect of the picture at the beginning of the article. Neon lights in different colorsWhat if you want neon light effects in other colors? Do I need to modify the relevant colors again? In fact, we have a simpler method, which is to use filter:hue-rotate(20deg) to modify the hue/tone of div.light and all internal elements at once.
The final effect is as follows: This is the end of this article about how to achieve cool neon light effects with pure CSS (with demo). For more relevant CSS neon light content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Ubuntu boot auto-start service settings
>>: Detailed explanation of MySQL trigger trigger example
See the effect first Implementation Code <div ...
This article example shares the specific code of ...
Table of contents Optimization of if judgment 1. ...
This article records the method of sharing files ...
Preface: In daily study and work, we often encoun...
Table of contents 1. Scenario 2. Basic functions ...
Encryption and decryption are an important means ...
1. Search for redis image docker search redis 2. ...
Preface I wrote a few examples using vue3, and I ...
Preface The "destructuring assignment syntax...
How to uninstall Mysql perfectly? Follow the step...
Table of contents 1. Declare a function 2. Callin...
Dockerfile is a file used to build a docker image...
Overview es6 adds a new way to get specified elem...
Table of contents Overview definition Instance Me...