Categories
CSS

How to select the first element with class with CSS?

Spread the love

Sometimes, we want to select the first element with class with CSS.

In this article, we’ll look at how to select the first element with class with CSS.

How to select the first element with class with CSS?

To select the first element with class with CSS, we the first-of-type.

For instance, we write

.red:first-of-type {
  color: red;
}

to select the first element with class red with .red:first-of-type.

Conclusion

To select the first element with class with CSS, we the first-of-type.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *