I have some code that isn't working and I'm not sure why.
The html looks like this:
<section>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
The CSS looks like:
section {
min-height: 200px;
}
section:nth-child(odd) {
background: #F5E9DE;
}
section:nth-child(even) {
background: #fefcfb;
}
section:nth-last-child(2) {
background: #B97459;
}
section:last-child {
background: #38292c;
}
Fiddle: https://jsfiddle.net/bxuzs3g0/8/
The idea is simple, alternate the odd and even backgrounds, then the last two sections should have specific background colors. This way I can have as many sections as I want, but the last two sections always have specific background colors.
I'm not sure what I'm doing wrong here, I have tried nth-last-child(1)
and last-child
, but for some reason neither combination is working for me.
I know this one's probably pretty easy, can anyone point me in the right direction?
Thanks,
Josh