Change specific div, nth-child?

Kim Kakan Andersson picture Kim Kakan Andersson · Jan 22, 2013 · Viewed 22.2k times · Source

I have a problem here. I have this div that's mentioned 4 times in my code, like:

<div class='box1'>
Hello 1
</div>
<div class='box1'>
Hello 2
</div>
<div class='box1'>
Hello 3
</div>
<div class='box1'>
Hello 4
</div>

and I want to do some changes to this div class, but only the last one. I cant get the nth-class to work, it seems that i need to make a ul table for it to work? Can I get a workaround somewhere in the CSS and make it work without having to rewrite my code?

Answer

Sheixt picture Sheixt · Jan 22, 2013

You should be able to do this with the nth-child pseudo class. Take a look at this demo: http://jsfiddle.net/m7uW7/2/