Reputation: 1
i have a problem that if i type 1 nothing happen, but if i type 2 it make changes to the first div :S.
do you know what im doing wrong
Upvotes: 0
Views: 87
Reputation: 43823
:nth-child()
is 1-indexed and :nth-child(1)
will select the first child. If it is not selecting what you want, there must be another child that is actually first. Maybe it's the header… in your example image.
Since it is the header (thanks for the link to your site), you should use :nth-of-type()
instead to consider just the <div class="newsPost">
when counting.
Upvotes: 2
Reputation: 15220
It's because the first and the last child have their own selectors:
:first-child
and
:last-child
So you have to use .newsPost:firstChild
instead of .newsPost:nth-child(1)
.
Upvotes: 0