2

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>
1
  • If you didn't put the spans in divs, nth-child would work.. Putting single spans in divs is rather redundant. Commented Aug 31, 2013 at 18:26

2 Answers 2

2

try this

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

}

where (n) will be number of the div

Sign up to request clarification or add additional context in comments.

2 Comments

@Travis he want to target span individually by its parent div how can it be done without it
@Travis yes my first expression was that too, that you have misread the question
1

Try this

div>div>span{

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.