Not exactly sure, but I think you are trying to do something like this:
ul li:nth-last-of-type(1){background:red}
ul li:nth-last-of-type(3){background:blue}
<ul>
<li class="selected">un</li>
<li class="selected">deux</li>
<li class="selected"> ---- I want select that one ----- </li>
<li class="foo">quatre</li>
<li>cinq</li>
<li class="tang">six</li>
</ul>
Note: For using nth-child or nth-last-of-type, you will have to make selection of element, for classes it won't work.
If you are trying to name the item and then count it from top or bottom, this won't work in CSS as per now.
Either you will have to use jQuery or some JavaScript library (for dynamic counting) or else you will have to point out element (somehow using CSS Selectors) and then make CSS changes.
Note: Current CSS3 specification does not provide selecting classes based on counting. So, if you are trying to count classes and use either of nth-child, nth-last-child, nth-of-type, nth-last-of-type
you will be highly dissapointed as they will couunt based on Elements, for example ul li
but will not take into consideration of class while counting, for example ul li.selected:nth-child(3)
. So, this will be rendered unuseful in your case.
Using jQuery:
You got 2 options - a) :last
b) .last()
$(document).ready(function(){
$('.selected:last').css('background', 'red')
$( '.selected' ).last().css( "color", "blue" );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<ul>
<li class="selected">un</li>
<li class="selected">deux</li>
<li class="selected"> ---- I want select that one ----- </li>
<li class="foo">quatre</li>
<li>cinq</li>
<li class="tang">six</li>
</ul>