🎓 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 line-through or strikethrough effect on text in CSS is a simple way to indicate removed or outdated content. The text-decoration property can be used to apply this effect.
Problem Statement
Create a CSS code that:
- Adds a strikethrough effect to text using the
text-decorationproperty. - Demonstrates how to customize the strikethrough style.
Example:
- Input: A paragraph element with the text "Strikethrough Example".
- Output: The text appears with a line-through (strikethrough) applied.
Solution Steps
- Use
text-decorationProperty: Settext-decorationtoline-throughto apply the strikethrough effect. - Customize the Line-Through: Use different values for
text-decorationto modify the style (e.g., color, thickness).
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Strikethrough Text Example</title>
<style>
/* Step 1: Add strikethrough to text */
.line-through-text {
text-decoration: line-through;
}
/* Step 2: Customize the strikethrough color and style */
.custom-line-through {
text-decoration: line-through;
text-decoration-color: red;
text-decoration-thickness: 2px;
}
</style>
</head>
<body>
<p class="line-through-text">This text is struck through using text-decoration: line-through.</p>
<p class="custom-line-through">This text has a custom strikethrough with color and thickness.</p>
</body>
</html>
Output
Explanation
Step 1: Use text-decoration: line-through
- To add a strikethrough to text, use this CSS code:
.line-through-text { text-decoration: line-through; }
Step 2: Customize the Strikethrough
- To customize the strikethrough color and thickness, use this CSS code:
.custom-line-through { text-decoration: line-through; text-decoration-color: red; text-decoration-thickness: 2px; }
Conclusion
You can easily create a strikethrough effect on text using the text-decoration: line-through property. Additionally, you can customize the strikethrough color and thickness to match your design needs.
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