nth-of-type always looks at the index of an element relative to its direct parent: ( w3schools ), so it wonβt work on the whole page.
It is best to implement this behavior using javascript, here's a quick demo using jQuery: jsfiddle
var styles = ["first", "second", "third"]; var index = 0; $("body").find("a").each(function() { $(this).addClass(styles[index++]); if (index >= styles.length) index = 0; });
source share