I'm facing a problem regarding overriding of css, any help will be appreciated.
We have a list of elements where some of the 'li' have active class
<ul class="the_track">
<li class="active">One</li>
<li class="active">Two</li>
<li class="active">Three</li>
<li class="active">Four</li>
<li class="active">Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
</ul>
By default all of these have background of "#CCC".
ul.the_track li{
background:#CCC;
}
All the li with 'active' class has the background of '#F00' overrides '#CCC'
ul.the_track li.active{
background:#F00;
}
Now coming to the problem area, as per my requirement I want the active class to be overridden again.
ul.the_track li.active:first-child{
/* this is working */
background:#777;
}
but,
ul.the_track li.active:last-child{
/* this should not work */
background:#CCC;
}
so, basically the first-child overriding is working where last-child is not,as it is not the last child of container but how to access this last child is there any alternate CSS solution without involving JS ?.
Here is a snippet for the above code
( For codepen lovers http://codepen.io/shyamaprasad/pen/WGQjXk ) :
ul.the_track li{
background:#CCC;
}
ul.the_track li.active{
background:#F00;
}
ul.the_track li.active:first-child{
/* this is working */
background:#777;
}
ul.the_track li.active:last-child{
/* this one should not work */
background:#CCC;
}
<ul class="the_track">
<li class="active">One</li>
<li class="active">Two</li>
<li class="active">Three</li>
<li class="active">Four</li>
<li class="active">Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
</ul>