Home Web Front-end HTML Tutorial Examples of dynamic text effects using pure CSS

Examples of dynamic text effects using pure CSS

Jun 05, 2018 am 11:49 AM
css dynamic letter

I believe everyone has seen the medium effect on the website. Once the page is opened, both text and pictures change with the specified time. Today we will introduce how to achieve this effect by using pure CSS. Let’s take a look below.

You may often see cool websites

You can see in this type of website that as soon as the page is opened, both text and pictures change with the specified time. The principle is very simple, mainly using the animation attribute in CSS.

Next, I will take my current project as an example to achieve the animation effect of text and pictures.

HTML code writing:

##Copy code

The code is as follows:

<section class="rw-wrapper">
<span class="span-title">文字题目</span>
<h2 class="rw-sentence">
</h2>
</section>
Copy after login

At present, the general framework has been written, including a section tag, span (add according to preference), and h2 tag. Next add text code to it. Put the code in h2.

Copy code

The code is as follows:

<p class="rw-words rw-words-1">
<span>内容1</span>
<span>内容2</span>
...
</p>
Copy after login

The first text animation HTML.

Copy code

The code is as follows:

<p class="rw-words rw-words-2">
<span>内容1</span>
...
</p>
Copy after login

The second type of text animation HTML.

Copy code

The code is as follows:

//同理
<p class="rw-words rw-words-3">
<span><img src="图片路径" width="XX" height="XX"></span>
...
</p>
Copy after login

The image transformation effect is as shown in the GIF above. Pictures slide from the right and change.

ok, now that the HTML code is done, now let’s implement the core part: CSS animation and font styles.

CSS code writing

Copy code

The code is as follows:

.rw-words{
-webkit-perspective:800px;
-moz-perspective:800px;
-o-perspective:800px;
-ms-perspactive:800px;
perspactive:800px;
}
Copy after login

By the way, the perspective attribute defines the distance of the 3D element from the view, in pixels. When you define the perspective attribute for an element, its child elements get the perspective effect, not the element itself. The number 800px represents the distance of the element from the view. -moz represents firefox browser private properties, -ms represents IE browser private properties, -webkit represents chrome and safari private properties, -o represents opera browser private properties.

Copy code ##The code is as follows:

.rw-words span{
white-space:nowrap; //文字不允许换行
overflow:hidden;
}
Copy after login

The specific label position settings are set according to the actual situation.

Copy codeThe code is as follows:

.rw-words-1 span{
-webkit-animation: rotateWordsFirst 10s linear infinite 0s;
-o-animation: rotateWordsFirst 10s linear infinite 0s;
-moz-animation: rotateWordsFirst 10s linear infinite 0s;
-ms-animation: rotateWordsFirst 10s linear infinite 0s;
animation:rotateWordsFirst 10s linear infinite 0s;
}
Copy after login

Use animation effects here! First, rotateWordsFirst is the name of the animation, 10s is the time it takes for the entire animation to be completed once, linear is the time curve used, and infinite is repeated an unlimited number of times.

About animation syntax:

##Copy code

The code is as follows:

animation: name duration timing-function delay iteration-count direction;
Copy after login

animation-name: Specifies the keyframe name that needs to be bound to the selector.

animation-duration: Specifies the time it takes to complete the animation, in seconds or milliseconds.

animation-timing-function: Specifies the speed curve of animation.

animation-delay: Specifies the delay before the animation starts.

animation-iteration-count: Specifies the number of times the animation should be played (infinite rotation)

animation-direction: Specifies whether the animation should be played in reverse in turn.

If you want to know more, search: CSS series animationi.

Next, another type of animation.

Copy code

The code is as follows:

.rw-words-2 span{
-webkit-animation: rotateWordsFirst 10s ease-in infinite 0s;
-o-animation: rotateWordsFirst 10s ease-in infinite 0s;
-moz-animation: rotateWordsFirst 10s ease-in infinite 0s;
-ms-animation: rotateWordsFirst 10s ease-in infinite 0s;
animation:rotateWordsFirst 10s ease-in infinite 0s;
}
Copy after login

ease-in explanation:

ease is stipulated to be slow A transition effect that starts at a slow speed, then becomes faster, and then ends at a slow speed; ease-in specifies a transition effect that starts at a slow speed; ease-out specifies a transition effect that ends at a slow speed; ease-in-out specifies a transition effect that starts at a slow speed and ends at a slow speed Ending transition effect (you can try these effects)

Similarly, the .rw-words-3 span can be set in the same way.

Copy code

The code is as follows:

.rw-words span:nth-child(1){
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
-o-animation-delay: 3s;
-ms-animation-delay: 3s;
animation-delay: 3s;
}
Copy after login

:nth-child(n) selector matches the element that belongs to its parent The Nth child element of , regardless of the element's type. n can be a number, keyword, or formula.

Copy code

The code is as follows:

.rw-words span:nth-child(n) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
...
Copy after login

Set different selectors to achieve display delay between text .

Copy code

The code is as follows:

@-webkit-keyframes rotateWordsFirst/second {
0% { opacity: 0; -webkit-animation-timing-function: ease-in; width: 0px;}
//此属性查看animation
5% { opacity: 1; -webkit-animation-timing-function: ease-out; width: 100%;}
17% { opacity: 1; } //设置不透明级别
20% { opacity: 0; }
100% { opacity: 0; }
}
Copy after login

keyframes defines the timeline for each animation, and you can set a certain time What is the state of the element being animated. Used with animation.

Then write the adaptation of each browser, such as -o, -moz, -ms, etc.

In addition to the animation attribute, you can also try the use of the transform attribute, which can achieve effects such as rotation and scaling of text and images. The above is all about using pure CSS to achieve dynamic text effects. I hope it can help It helps everyone learning to use CSS.

Related recommendations:

CSS text font color setting method (CSS color)

The above is the detailed content of Examples of dynamic text effects using pure CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles