🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Introduction
Creating a bouncing text animation in CSS adds dynamic movement to your web page, drawing attention to important content. This effect can be achieved using @keyframes to define the animation and the transform property to simulate the bounce.
In this tutorial, you'll learn how to create a bouncing text animation using HTML and CSS.
Problem Statement
Create a CSS code that:
- Animates text to bounce up and down using the
@keyframesandtransformproperties. - Demonstrates how to control the bounce speed and height.
Example:
- Input: A paragraph element with the text "Bouncing Text Animation".
- Output: The text bounces up and down continuously.
Solution Steps
- Use
@keyframesfor Bounce Animation: Create keyframes to define the bounce motion. - Apply the Bounce Effect to Text: Use the
animationproperty to control the bouncing speed and repetition.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bouncing Text Animation</title>
<style>
/* Step 1: Define keyframes for the bounce animation */
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0); /* Start and end at the original position */
}
40% {
transform: translateY(-30px); /* Move up */
}
60% {
transform: translateY(-15px); /* Move up slightly */
}
}
/* Step 2: Apply bounce effect to text */
.bouncing-text {
font-size: 3rem;
color: #3498db;
animation: bounce 2s infinite; /* 2-second bounce animation, infinite loop */
font-family: Arial, sans-serif;
text-align: center;
margin-top: 100px;
}
/* Center the container */
.container {
text-align: center;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="container">
<p class="bouncing-text">Bouncing Text Animation</p>
</div>
</body>
</html>
Output
Explanation
Step 1: Define @keyframes for Bounce Animation
The
@keyframesrule defines the bounce movement. The text moves up and down in a bouncing motion using thetransform: translateY()property:@keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); /* Start and end at the original position */ } 40% { transform: translateY(-30px); /* Move up */ } 60% { transform: translateY(-15px); /* Move up slightly */ } }At
40%in the animation timeline, the text moves up by-30px, creating the upward bounce. At60%, it moves up slightly by-15px, simulating the natural bounce back.
Step 2: Apply the Bounce Effect to Text
To apply the bounce animation to the text, use the
animationproperty:.bouncing-text { animation: bounce 2s infinite; }The
2sduration defines the length of the bounce cycle, andinfiniteensures that the animation loops continuously.
Conclusion
Creating a bouncing text animation in CSS is simple using @keyframes and the transform property. This effect adds fun, dynamic motion to your text, making it visually engaging and helping important messages stand out on your web page.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment