Axl
Axl

Reputation: 67

How to target individually nested elements using CSS

I'm trying to target each span individually in a structure like below. I've tried nth-child() & nth-of-type() but it didn't work, it was only applying the first style to all of the spans. Anyone no know how to do this without giving each a separate IDs?

<div>
  <div>
    <span></span>
  </div>
  <div>
    <span></span>
  </div>
  <div>
    <span></span>
  </div>
</div>

Upvotes: 2

Views: 440

Answers (2)

Nitesh
Nitesh

Reputation: 484

Try this

div>div>span{

}

Upvotes: 1

Hushme
Hushme

Reputation: 3144

try this

div > div:nth-of-type(n) > span {

}

where (n) will be number of the div

Upvotes: 2

Related Questions