1

Possible Duplicate:
CSS selector for first element with class

Currently I have a code that looks something like this:

<div class="content">
   <div style="...">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
</div>

How can I target the first "post" class in this example? In other words, what CSS selector do I have to use?

<div class="content">
   <div style="...">...</div>
   <div class="post">...</div> <--- I need a selector to edit the styles for this.
   <div class="post">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
   <div class="post">...</div>
</div>

Any help would be highly appreciated! Thanks!

Community
  • 1
  • 1
user1676019
  • 108
  • 1
  • 6
  • Have you tried .post:first-child ? – Vucko Nov 20 '12 at 23:52
  • Neither `.post:first-child` nor `.post:first-of-type` will work. See my answer to the duplicate question. In your case, you need two rules: one for `.content .post`, and another for `.content .post ~ .post` to undo the styles for subsequent `.post` elements. – BoltClock Nov 21 '12 at 04:03

1 Answers1

3

You need the nth-child selector

.post:nth-child(2)
{
//css
}

Fiddle

Sidharth Mudgal
  • 4,234
  • 19
  • 25