🎓 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
Highlighted text in CSS can be created to draw attention to specific parts of your content. Using the background-color property, you can easily apply a background color to the text, making it stand out.
In this tutorial, you'll learn how to create highlighted text using CSS by applying a background color to specific text elements.
Problem Statement
Create a CSS code that:
- Highlights text by applying a background color.
- Demonstrates how to apply the
background-colorproperty to various text elements.
Example:
- Input: A span element with the text "Highlighted Text Example".
- Output: The text appears with a highlighted background color.
Solution Steps
- Use
background-colorProperty: Apply thebackground-colorproperty to highlight the text with a specific color. - Wrap Text with a
span: Use aspanelement to target specific parts of the text for highlighting.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Highlighted Text Example</title>
<style>
/* Step 1: Highlight text with background color */
.highlight {
background-color: yellow;
padding: 2px;
}
</style>
</head>
<body>
<p>This is an example of <span class="highlight">highlighted text</span> using CSS.</p>
</body>
</html>
Output
Explanation
Step 1: Use background-color: yellow
To highlight text with a background color, use this CSS:
.highlight { background-color: yellow; padding: 2px; }The
background-color: yellowproperty adds a yellow highlight to the text, and thepadding: 2pxensures the highlight doesn’t touch the text closely.
Step 2: Wrap the Text with a span
- To highlight only a specific portion of the text, wrap it with a
spanelement and apply thehighlightclass.
Conclusion
Creating highlighted text in CSS is easy using the background-color property. You can target specific text with a span element and apply a custom background color to make it stand out. This method is useful for emphasizing important information in your content.
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