CSS :first-child
The :first-child CSS pseudo-class represents the first element among a group of sibling elements. It targets an element that is the first child of its parent element.
Let's take a look at how to use the :first-child pseudo-class with some examples:
In the example above, we have an unordered list (<ul>) with three list items (<li>). We apply the :first-child pseudo-class to the <li> element to change the color of the first item to red.
Here's another example using different HTML elements:
In this example, we have a <div> element containing two paragraphs and a <span> element. We use the :first-child pseudo-class to make the first paragraph bold.
By using the :first-child pseudo-class, you can target specific elements within a group of siblings and apply different styles or effects to them.