tags:

views:

32

answers:

3

I have this the html below and in my CSS I write .CommentSection :nth-child(5n)

Instead of every 5th comment box being changed li .Hide is being changed an other elements. How do I make it so only the direct children (always div class="comment") are counted and applied to and not counting its children?

<div class="CommentSection">
  <div class="comment" id="c19">
    <ul>
        <li class="username">a</li>
        <li class="date">3/2/2010 6:14:51 AM</li>
        <li class="link"><a href="http://localhost:1223/u/a#c19"&gt;Permalink&lt;/a&gt;&lt;/li&gt;
        <li class="flag">Flag</li>
        <li class="Hide"><a href="http://localhost:1223/u?hide=1&amp;amp;t=8&amp;amp;c=19&amp;amp;ret=/u/a"&gt;Hide&lt;/a&gt;&lt;/li&gt;
        <li class="delete">Delete</li>
        <li class="reply">Reply</li>
    </ul>

    <div class="text">
      <p>asd</p>
    </div>
  </div>
...
</div>
+2  A: 

.CommentSection > :nth-child(5n) or .CommentSection .comment:nth-child(5n)

Alexander Gyoshev
+2  A: 

Try this:

.CommentSection > div.comment:nth-child(5n)

This will select every 5th DIV with the class comment that is a direct child of CommentSection.

Gumbo
overspecifying the selector makes it slower, as it needs to be matched on all of its parts... :S
Alexander Gyoshev
A: 

Try this

.CommentSection .comment:nth-child(5n){
  […]
}

Or more specific:

.CommentSection > .comment:nth-child(5n) {
  […]
}

This should work fine as well:

.CommentSection > :nth-child(5n) {
  […]
}
Nils Riedemann