Organize and share 5 pure CSS to achieve cool text effects
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
background: linear-gradient(90deg, black 0%, white 50%, black 100%);Set the webkit-background-clip property and use the text as the cropping area to crop outwards
-webkit-background-clip: text; background-clip: text;Set animation through the -webkit-animation property , you can achieve the above effect
-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%; } }Style reference
<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%; }This effect is also achieved using background-clip:text and the linear gradient attribute linear-gradient. The rainbow text effect is achieved by setting the regional color value. Dynamic rainbow text needs to set the -webkit-animation attribute
-webkit-animation: maskedAnimation 4s infinite linear; @keyframes maskedAnimation { 0% { background-position: 0 0; } 100% { background-position: -100% 0; } }CSS style
.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
.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
.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>The white-space:nowrap attribute is mainly to ensure that one line is displayed. Considering the display of English letters, this attribute is removed to ensure that there will be no character discontinuity. word-break:break-all enables English characters to be presented one by one. The steps function in the animation attribute allows the animation to be executed intermittently rather than continuously. The syntax of steps() is: steps(number, position), where the number keyword indicates how many segments the animation is divided into; the position keyword indicates whether the animation is continuous from the beginning or end of the time period, and supports start and The two keywords end have the following meanings:
- start: means starting directly
- end: means stopping abruptly, which is the default value
5. Fault style text effect
<div class="text" data-text="欢迎关注微信公众号【前端实验室】"> 欢迎关注微信公众号【前端实验室】 </div>Custom attributes are mainly used here, data- plus the custom attribute name, and the text to be displayed is assigned for the pseudo element to obtain the corresponding text.
@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); } }Two keyframes are set up here, namely animation-before and animation-after. The former is for pseudo-element before, and the latter is for pseudo-element after. The clip-path attribute is a new property mask of CSS3. The inset() value indicates that the shape of the mask is a rectangle. After defining the mask's effect area, set the frame-by-frame animation through @keyframes. Make the mask's area of effect change in the vertical direction to achieve the effect of up and down jittering.
.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; }Finally, we set two pseudo elements before and after, position them at the same position as the parent element, and then move them a little distance to the left and right respectively to create a misaligned effect, and then move them both The background color is set to the same color as the background color of the parent element, which is used to block the parent elementThis way, a perfect glitch-style text display animation can be achieved~Cool special effects It can add a different style to our web pages. The source code of the effect achieved in this article has been uploaded to Github. You can get it by replying to the aaa text effect in the background of the public account. Come and learn with us! (Learning video sharing:
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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Backdrop-filter is used to apply visual effects to the content behind the elements. 1. Use backdrop-filter:blur(10px) and other syntax to achieve the frosted glass effect; 2. Supports multiple filter functions such as blur, brightness, contrast, etc. and can be superimposed; 3. It is often used in glass card design, and it is necessary to ensure that the elements overlap with the background; 4. Modern browsers have good support, and @supports can be used to provide downgrade solutions; 5. Avoid excessive blur values and frequent redrawing to optimize performance. This attribute only takes effect when there is content behind the elements.

User agent stylesheets are the default CSS styles that browsers automatically apply to ensure that HTML elements that have not added custom styles are still basic readable. They affect the initial appearance of the page, but there are differences between browsers, which may lead to inconsistent display. Developers often solve this problem by resetting or standardizing styles. Use the Developer Tools' Compute or Style panel to view the default styles. Common coverage operations include clearing inner and outer margins, modifying link underscores, adjusting title sizes and unifying button styles. Understanding user agent styles can help improve cross-browser consistency and enable precise layout control.

The style of the link should distinguish different states through pseudo-classes. 1. Use a:link to set the unreached link style, 2. a:visited to set the accessed link, 3. a:hover to set the hover effect, 4. a:active to set the click-time style, 5. a:focus ensures keyboard accessibility, always follow the LVHA order to avoid style conflicts. You can improve usability and accessibility by adding padding, cursor:pointer and retaining or customizing focus outlines. You can also use border-bottom or animation underscore to ensure that the link has a good user experience and accessibility in all states.

The best use scenario for CSS will-change attribute is to inform browser elements in advance of possible changes in order to optimize rendering performance, especially for animation or transition effects. ① It should be applied before the animation properties (such as transform, opacity or position) changes; ② Avoid premature use or long-term retention, and should be set before the change occurs and removed after completion; ③ It should only be used for necessary properties rather than using will-change:all; ④ Suitable for scenarios such as large scrolling animations, interactive UI components, and complex SVG/Canvas interfaces; ⑤ Modern browsers can usually optimize automatically, so there is no need to use will-change in all animations. Proper use can improve

Define@keyframesbouncewith0%,100%attranslateY(0)and50%attranslateY(-20px)tocreateabasicbounce.2.Applytheanimationtoanelementusinganimation:bounce0.6sease-in-outinfiniteforsmooth,continuousmotion.3.Forrealism,use@keyframesrealistic-bouncewithscale(1.1

Tocenteradivhorizontally,setawidthandusemargin:0auto.2.Forhorizontalandverticalcentering,useFlexboxwithjustify-content:centerandalign-items:center.3.Alternatively,useCSSGridwithplace-items:center.4.Forolderbrowsers,useabsolutepositioningwithtop:50%,l

Theaspect-ratioCSSpropertydefinesthewidth-to-heightratioofanelement,ensuringconsistentproportionsinresponsivedesigns.1.Itisapplieddirectlytoelementslikeimages,videos,orcontainersusingsyntaxsuchasaspect-ratio:16/9.2.Commonusecasesincludemaintainingres

To achieve CSS element overlap, you need to use positioning and z-index attributes. 1. Use position and z-index: Set elements to non-static positioning (such as absolute, relative, etc.), and control the stacking order through z-index, the larger the value, the higher the value. 2. Common positioning methods: absolute is used for precise layout, relative is used for relatively offset and overlap adjacent elements, fixed or sticky is used for fixed positioning of suspended layers. 3. Actual example: By setting the parent container position:relative, child element position:absolute and different z-index, the card overlap effect can be achieved.
