Stylish Drop Cap Technique

CSSCSSBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will learn about the Drop Cap technique in CSS. Drop Cap is a typographic technique used to add visual appeal to the first letter of the first paragraph. Through this lab, you will understand how to use the :first-child selector and the ::first-letter pseudo-element to style the first letter of a paragraph in a unique and eye-catching way.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL css(("`CSS`")) -.-> css/BasicConceptsGroup(["`Basic Concepts`"]) css(("`CSS`")) -.-> css/BasicStylingGroup(["`Basic Styling`"]) css(("`CSS`")) -.-> css/CoreLayoutGroup(["`Core Layout`"]) css(("`CSS`")) -.-> css/IntermediateStylingGroup(["`Intermediate Styling`"]) css/BasicConceptsGroup -.-> css/selectors("`Selectors`") css/BasicStylingGroup -.-> css/colors("`Colors`") css/BasicStylingGroup -.-> css/fonts("`Fonts`") css/CoreLayoutGroup -.-> css/margin_and_padding("`Margin and Padding`") css/CoreLayoutGroup -.-> css/width_and_height("`Width and Height`") css/IntermediateStylingGroup -.-> css/pseudo_classes("`Pseudo-classes`") css/IntermediateStylingGroup -.-> css/pseudo_elements("`Pseudo-elements`") subgraph Lab Skills css/selectors -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/colors -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/fonts -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/margin_and_padding -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/width_and_height -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/pseudo_classes -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} css/pseudo_elements -.-> lab-35193{{"`Stylish Drop Cap Technique`"}} end

Drop Cap

You can write the code in index.html and style.css.

Makes the first letter of the first paragraph bigger than the rest of the text.

  • Use the :first-child selector to select only the first paragraph.
  • Use the ::first-letter pseudo-element to style the first element of the paragraph.
<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam commodo
  ligula quis tincidunt cursus. Integer consectetur tempor ex eget hendrerit.
  Cras facilisis sodales odio nec maximus. Pellentesque lacinia convallis
  libero, rhoncus tincidunt ante dictum at. Nullam facilisis lectus tellus, sit
  amet congue erat sodales commodo.
</p>
<p>
  Donec magna erat, imperdiet non odio sed, sodales tempus magna. Integer vitae
  orci lectus. Nullam consectetur orci at pellentesque efficitur.
</p>
p:first-child::first-letter {
  color: #5f79ff;
  float: left;
  margin: 0 8px 0 4px;
  font-size: 3rem;
  font-weight: bold;
  line-height: 1;
}

Summary

Congratulations! You have completed the Drop Cap lab. You can practice more labs in LabEx to improve your skills.

Other CSS Tutorials you may like