How to use a CSS selector for the first direct child only?

Spread the love

Sometimes, we want to use a CSS selector for the first direct child only.

In this article, we’ll look at how to use a CSS selector for the first direct child only.

How to use a CSS selector for the first direct child only?

To use a CSS selector for the first direct child only, we use the > operator.

For instance, we write

div.section > div:first-child {
  //...
}

to select the first direct child div of the div with class section with > and first-child.

Conclusion

To use a CSS selector for the first direct child only, we use the > operator.

Leave a Reply

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