Open In App

Explain the purpose of using the CSS box-sizing Property

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In CSS, targeting only the first child of an element is useful for applying styles exclusively to the first child element within a container. The :first-child pseudo-class is used to select and style the first child element.

Syntax

/* Selecting and styling the first <p> element within a container */
.container p:first-child {
font-weight: bold;
}

/* Selecting and styling the first child of any type within a container */
.container :first-child {
color: red;
}

Features

  • :first-child Pseudo-class: Targets the first child element of its parent.
  • Specific Element Type: It can be used to select the first child of a specific type within a container.
  • Universal Selector: It can also be applied using the universal selector (*) to select the first child regardless of its type.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads