🎓 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
A rotating text effect can add dynamic and interactive visuals to your web page. This effect can be easily achieved using CSS @keyframes and the transform property with rotate().
In this tutorial, you'll learn how to create a rotating text effect using HTML and CSS.
Problem Statement
Create a CSS code that:
- Animates text to rotate continuously using
@keyframesandtransform: rotate(). - Demonstrates how to control the rotation speed and repetition.
Example:
- Input: A heading element with the text "Rotating Text Effect".
- Output: The text rotates continuously.
Solution Steps
- Use
@keyframesfor Rotation Animation: Define keyframes to animate the text's rotation. - Apply the Rotation Effect to Text: Use the
animationproperty to control the rotation duration 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>Rotating Text Animation</title>
<style>
/* Step 1: Define keyframes for rotating text */
@keyframes rotateText {
0% {
transform: rotate(0deg); /* Start rotation at 0 degrees */
}
100% {
transform: rotate(360deg); /* Full rotation (360 degrees) */
}
}
/* Step 2: Apply rotation effect to text */
.rotating-text {
font-size: 3rem;
color: #e74c3c;
font-family: Arial, sans-serif;
text-align: center;
animation: rotateText 4s linear infinite; /* 4s rotation, infinite loop */
margin-top: 100px;
}
/* Center the text */
.container {
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h1 class="rotating-text">Rotating Text Effect</h1>
</div>
</body>
</html>
Output
Explanation
Step 1: Define @keyframes for Rotating Text
- The
@keyframesrule defines the rotation movement. It starts at0degand ends at360degto complete one full rotation:@keyframes rotateText { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
Step 2: Apply the Rotation Effect to Text
To apply the rotation effect to the text, use the
animationproperty:.rotating-text { animation: rotateText 4s linear infinite; }The
4sspecifies that the text will take 4 seconds to complete one full rotation, andinfiniteensures that the rotation continues indefinitely.The
linearkeyword ensures that the rotation happens at a constant speed throughout the animation.
Step 3: Center the Text
- Use
text-align: centerto center the text within the page and add a margin for spacing:.container { text-align: center; }
Conclusion
Creating a rotating text effect with CSS is simple using @keyframes and the transform: rotate() property. This effect can add dynamic movement to your text, making it visually engaging and interactive 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