I have a navigation menu that assigns an array of colors to menu items based on their depth in the menu / taxonomy hierarchy. So, for example, all the top-level menu items get the color black, the next level turns red, the next level turns green, etc., And since the hierarchy goes very deep, I would like to target using math, it’s kind of like css can target nth-child. However, I cannot use nth-child because these container elements ("browse level") are dynamically added and removed from the DOM (they are not all in the DOM at the same time), so I target data attributes.
So here is 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.
8 ( ). ( LESS CSS) ?