1

Possible Duplicates:
CSS selector for first element with class
CSS selector to select first element of a given class

I have an HTML structure here.

<div id = "container">
    <p class = "txt">abc</p>
    <p class = "vs">123</p>
    <p class = "txt">abc</p>
    <p class = "txt">abc</p>
    <p class = "vs">456</p>
</div>

How could I select the first p whose class is "vs" to set the font color to "red" via CSS selector? I mean the expectation is that only 123 is red, but 456 and abc are black.

Thanks in advance.

Community
  • 1
  • 1
user1338323
  • 73
  • 1
  • 4
  • 7
    possible duplicate of [CSS selector for first element with class](http://stackoverflow.com/questions/2717480/css-selector-for-first-element-with-class) and [CSS selector to select first element of a given class](http://stackoverflow.com/questions/3615518/css-selector-to-select-first-element-of-a-given-class) – BoltClock Apr 17 '12 at 09:24
  • Note that the accepted answer to the first duplicate doesn't get it right. You can't use `:nth-of-type(1)` or `:first-of-type` here as they are all p elements. – BoltClock Apr 17 '12 at 09:31
  • http://jsfiddle.net/bipin000/TWYTy/ particular to this scenario u can use css like this #container p.vs:nth-child(2n) { color:red; }​ – Bipin Chandra Tripathi Apr 17 '12 at 09:39

0 Answers0