Look at the HTML and CSS below.
This is the initial CSS
ul ul li:nth-last-of-type(2){
background: #ff0000;
}
<ul>
<li>bla
<ul>
<li>bla bla
<ul>
<li>bla bla bla</li>
<li>Gostaria que não fosse selecionado</li>
<li>bla bla bla</li>
</ul>
</li>
<li>Selecionado</li>
<li>bla bla</li>
</ul>
</li>
<li>bla
<ul>
<li>Selecionado</li>
<li>bla bla</li>
</ul>
</li>
<li>bla</li>
</ul>
The manual solution would do this
ul ul ul li:nth-last-of-type(2){
background: initial;
}
But I did not want to do that. Assuming that if I add to the ul
deeper in the hierarchy the li
below.
<li>
bla bla bla
<ul>
<li>Agora esse não deve mais ser selecionado</li>
<li>Bla bla bla bla</li>
</ul>
</li>
ul ul ul ul li:nth-last-of-type(2){
background: initial;
}
That is, this CSS is not sustainable. With each new node in ul
deeper I will have to maintain the CSS every time, adding a new ul
in the hierarchy to restart the property. How do I make it dynamic?