🎓 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
Styling text as small caps in CSS can give it a more formal or decorative look. Small caps transform lowercase letters into smaller uppercase letters while keeping actual uppercase letters larger.
In this tutorial, you'll learn how to style text as small caps using the font-variant property in CSS. This technique is commonly used for headings or to add emphasis in specific parts of a document.
Problem Statement
Create a CSS code that:
- Styles text as small caps using the
font-variantproperty. - Demonstrates how to apply the small caps effect to different HTML elements.
Example:
- Input: A paragraph element with the text "Small Caps Example".
- Output: The text is displayed in small caps.
Solution Steps
- Use
font-variant: small-caps: Apply thefont-variantproperty to transform lowercase letters into small caps. - Apply to Different Elements: Use
font-varianton various HTML elements likep,h1, orspanfor different text styles.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Small Caps Text Example</title>
<style>
/* Step 1: Style text with small caps */
.small-caps-text {
font-variant: small-caps;
}
/* Additional styling for headings with small caps */
.small-caps-heading {
font-variant: small-caps;
font-size: 2rem;
}
</style>
</head>
<body>
<p class="small-caps-text">This text is styled in small caps using font-variant: small-caps.</p>
<h1 class="small-caps-heading">This heading is in small caps.</h1>
</body>
</html>
Output
Explanation
Step 1: Use font-variant: small-caps
- To transform lowercase letters into small caps, use the following CSS:
.small-caps-text { font-variant: small-caps; }
Step 2: Apply Small Caps to Headings
- You can also apply small caps to headings or other elements for a more prominent effect:
.small-caps-heading { font-variant: small-caps; font-size: 2rem; }
Conclusion
Styling small caps text in CSS is easy using the font-variant: small-caps property. This technique gives your text a refined, formal look, and can be applied to both paragraphs and headings to enhance the visual hierarchy of 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