This article brings you 5 very cool text effects. These effects are all implemented using CSS. I hope it will be helpful to everyone.
CSS is a very special language. You think CSS can only be used to control the structure and style of web pages, but as long as you have rich imagination, you can create Endless possibilities.
1. Gradient text effect
## This effect mainly uses background-clip: text combined with color to achieve a gradient text effect. First, understand the meaning of background-clip: text;: use the text in the box as the cropping area to crop outwards, and the area outside the text will be cropped. Set a gradient background for the text container
background: linear-gradient(90deg, black 0%, white 50%, black 100%);
-webkit-background-clip: text; background-clip: text;
-webkit-animation: shining 3s linear infinite; animation: shining 3s linear infinite;
@-webkit-keyframes shining { from { background-position: -500%; } to { background-position: 500%; } } @keyframes shining { from { background-position: -500%; } to { background-position: 500%; } }
<html> <link rel="stylesheet" href="./css/neno-text-style.css"> <body> <p class="neon">前端实验室</p> </body> </html>
2. Rainbow text effect (marquee)
.text { letter-spacing: 0.2rem; font-size: 1.5rem; background-image: -webkit-linear-gradient(left, #147B96, #E6D205 25%, #147B96 50%, #E6D205 75%, #147B96); -webkit-text-fill-color: transparent; -webkit-background-clip: text; -webkit-background-size: 200% 100%; }
-webkit-animation: maskedAnimation 4s infinite linear; @keyframes maskedAnimation { 0% { background-position: 0 0; } 100% { background-position: -100% 0; } }
.rainbow { letter-spacing: 0.2rem; font-size: 1.2rem; text-transform: uppercase; } .rainbow span { animation: rainbow 50s alternate infinite forwards; } @keyframes rainbow { 0% { color: #efc68f; } ... 100% { color: #8fefed; } }
<html> <head> <link rel="stylesheet" href="./css/rainbow-color-text-style.css"> </head> <body> <div class="text">【前端实验室】分享前端最新、最实用前端技术</div> </body> </html>
3. Glowing text effect
This effect is mainly achieved using the text-shadow attribute. The text-shadow property adds one or more shadows to text. This property is a comma-separated list of shades, each shade specified with two or three length values and an optional color value.
.neon { color: #cce7f8; font-size: 2.5rem; -webkit-animation: shining 0.5s alternate infinite; animation: shining 0.5s alternate infinite; }
@-webkit-keyframes shining { from { text-shadow: 0 0 10px lightblue, 0 0 20px lightblue, 0 0 30px lightblue, 0 0 40px skyblue, 0 0 50px skyblue, 0 0 60px skyblue; } to { text-shadow: 0 0 5px lightblue, 0 0 10px lightblue, 0 0 15px lightblue, 0 0 20px skyblue, 0 0 25px skyblue, 0 0 30px skyblue; } }
<html> <head> <link rel="stylesheet" href="./css/neno-text-style.css"> </head> <body> <p class="neon">【前端实验室】分享前端最新、最实用前端技术</p> </body> </html>
4. Typewriter effect
This effect is mainly achieved by changing the width of the container..typing { color: white; font-size: 2em; width: 21em; height: 1.5em; border-right: 1px solid transparent; animation: typing 2s steps(42, end), blink-caret .75s step-end infinite; font-family: Consolas, Monaco; word-break: break-all; overflow: hidden; }
/* 打印效果 */ @keyframes typing { from { width: 0; } to { width: 21em; } } /* 光标 */ @keyframes blink-caret { from, to { border-color: transparent; } 50% { border-color: currentColor; } }
<html> <head> <link rel="stylesheet" href="./css/typing-style.css"> </head> <body> <div class="typing">【前端实验室】分享前端最新、最实用前端技术</div> </html>
5. Fault style text effect
The animation effect is relatively complex, mainly using CSS pseudo-elements, element custom attributes, mask attributes, animation animation, etc.
<div class="text" data-text="欢迎关注微信公众号【前端实验室】"> 欢迎关注微信公众号【前端实验室】 </div>
@keyframes animation-before{ 0% { clip-path: inset(0 0 0 0); } ... 100% { clip-path: inset(.62em 0 .29em 0); } } @keyframes animation-after{ 0% { clip-path: inset(0 0 0 0); } ... 100% { clip-path: inset(.29em 0 .62em 0); } }
.text{ display: inline-block; font-size: 3.5em; font-weight: 600; padding: 0 4px; color: white; position: relative; }
.text::before{ content: attr(data-text); position: absolute; left: -2px; width: 100%; background: black; text-shadow:2px 0 red; animation: animation-before 3s infinite linear alternate-reverse; }
.text::after{ content: attr(data-text); position: absolute; left: 2px; width: 100%; background: black; text-shadow: -2px 0 blue; animation: animation-after 3s infinite linear alternate-reverse; }
css video tutorial)
The above is the detailed content of Organize and share 5 pure CSS to achieve cool text effects. For more information, please follow other related articles on the PHP Chinese website!