0

Here's a codepen with my code massively simplified, and it still doesn't work. :nth-child works on the w3schools interactive coding page, so it isn't my computer.

.postPrevWrap:nth-child(odd) {
  background: red;
}
<div class="postPrevWrap">
  <div class="postPrev">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  </div>
  <div class="postPrev">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  </div>
</div>

https://codepen.io/anon/pen/dQzYwj

What am I doing wrong?

j08691
  • 204,283
  • 31
  • 260
  • 272
John S
  • 59
  • 8

1 Answers1

3

:nth-child should be applied to the child itself, not the wrapper:

So instead of:

.postPrevWrap:nth-child(odd)

do this:

.postPrev:nth-child(odd)
frontend_dev
  • 1,693
  • 14
  • 28