0

So I have html code which looks something like this:

.parent-div :first-child {
  background: rgba(0, 0, 0, 0.5)
}
<div class="parent-div">
  <div class="first-div">
    <div>First</div>
    <div>Second</div>
  </div>
  <div class="second-div">
    <div>First</div>
    <div>Second</div>
  </div>
</div>

I want :first-child to "return" only .first-div, but apart from that it also returns first children of children divs. How to fix that?

  • 3
    Use the child combinator instead of the descendant combinator. `.parent-div > :first-child` – CBroe May 13 '22 at 12:26

0 Answers0