This article mainly introduces the typing effect achieved by pure HTML+CSS, which has a certain reference value. If you are interested, you can learn more about it. Rendering analyzeAnimation can be thought of as three different levels:
The text is static, while the background in the middle and the cursor on the top are dynamic. Code html <div class="text">hello, world!</div> CSS :root { /* Number of characters */ --steps: 12; /* Animation time */ --duration: 2.5s; /* Font size */ --fontSize: 50px; /* cursor size */ --cursorSize: 20px; } .text { color: #333;; position: relative; display: inline-block; font-family: 'Courier New', Courier, monospace; font-size: var(--fontSize); line-height: 1; } .text::after { content: ''; width: var(--cursorSize); height: var(--fontSize); background-color: black; z-index: 2; position: absolute; animation: blink 1s var(--duration) step-end infinite, moveCursor var(--duration) steps(var(--steps)) forwards; } .text::before { content: ''; width: 100%; height: var(--fontSize); z-index: 1; position: absolute; background: linear-gradient(#fff, #fff) no-repeat top right; animation: showText var(--duration) steps(var(--steps)) forwards; } /* Cursor blinking animation*/ @keyframes blink { 0% { background-color: black; } 50% { background-color: transparent; } 100% { background-color: black; } } /* Cursor movement animation*/ @keyframes moveCursor { 0% { left: 0%; } 100% { left: 100%; } } /* Background moving animation */ @keyframes showText { 0% { background-size: 100% 100%; } 100% { background-size: 0% 100%; } } Note that the font must be monospaced. Because the distance the cursor moves each time is determined by the number of characters/total width. Online Demo This is the end of this article about how to achieve typing effects with pure HTML+CSS. For more relevant HTML+CSS typing effects content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: HTML+CSS to achieve surround reflection loading effect
>>: HTML+CSS to implement the sample code of the navigation bar drop-down menu
background: 1. There is a notification table in t...
Table of contents 1. Understanding the stack stru...
Preface: Because many business tables use design ...
Table of contents 1. Component Communication 1. P...
Table of contents Single-machine deployment Onlin...
Table of contents Case 1: Case 2: Case 3: To summ...
What if the basic images have been configured bef...
Earlier we talked about how to make a square with...
Preface The origin is a question 1: If your umask...
Table of contents 1 Node.js method of sending ema...
<br />Forms are an important channel for use...
This article example shares the specific code for...
Preface: MySQL is a relational database managemen...
Socat needs to be installed before installing rab...
usemap is an attribute of the <img> tag, use...