Horje
How to apply styles only to the first child of an element using CSS ?

The :first-child selector is a pseudo-class in CSS that enables you to target the initial child element within a parent container. This selector handpicks elements that are the first immediate child of their parent. It serves as a powerful selector that makes it easier to apply unique styles or modifications to that specific element.

 <div class="container">
<p>This is the first paragraph.</p>
<p>Second paragraph follows.</p>
<p>And here's the third paragraph.</p>
</div>

The basic syntax involves appending :first-child to the parent element’s selector. For instance, to style the first paragraph within a div:

Syntax:

div p:first-child {
/*Code */
}



Reffered: https://www.geeksforgeeks.org


Web Technologies

Related
What is the use of the float Property in CSS ? What is the use of the float Property in CSS ?
What is the purpose of the z-index Property ? What is the purpose of the z-index Property ?
What is the purpose of implementing the Semantic Elements in HTML ? What is the purpose of implementing the Semantic Elements in HTML ?
What are the Building Blocks of HTML? What are the Building Blocks of HTML?
When to use the placeholder attribute and the label Element ? When to use the placeholder attribute and the label Element ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12