I want to use css to select all elements until it reaches an element with a specific attribute. i.e.:
<ul>
<li>...</li>
<li>...</li>
<li class="active">...</li>
<li>...</li>
<li>...</li>
</ul>
I need to catch all <li>
elements that appear before the active
one. I know how to catch any group of child elements using nth-child etc., but active
changes, so it can't be a static group. And I know I can do it through javascript, but I wan't a css solution.
So is this possible to select all child elements up to a calculated point? Or in other words: is there a way to do a conditional nth-child? I'm willing to change the markup if needed (the attribute doesn't have to be a class, it can be anything).
Until recently I would've thought it's not possible, but after learning about the css attr()
I know it's possible to access the DOM attributes, so maybe it's also possible to take it a step further?