I have a navigational menu which assigns an array of colors to menu items based on their depth within a menu hierarchy / taxonomy. So, for example, all top level menu items get a color of black, next level gets red, next level gets green, etc, and because the hierarchy goes very deep, I'd like to target them using math, sort of the way that css can target nth-child. However, I can't use nth-child because these container elements ('browse-level') are dynamically added and removed from the DOM (they're not all in the DOM at the same time) which is why I'm target data attributes.
So here's the CSS:
.browse-level[data-level="1"] li a {
background: @level1;
}
.browse-level[data-level="2"] li a {
background: @level2;
}
.browse-level[data-level="3"] li a {
background: @level3;
}
.browse-level[data-level="4"] li a {
background: @level4;
}
... etc
There are 8 color values (after which the sequence would repeat). Can I (using LESS or plain CSS) shorten this code?