Please note: This answer presents a possible solution to the OP's specific problem which was clarified in a comment and does not necessarily address the problem in title of the question "How to apply css on anchor tag of nth list item?".
If you ...
- have control over URLs where these links point to, and
- don't expect those URL to change suddenly (unless you change the CSS, too),
... then you might want to use CSS attribute selectors.
Having this HTML specifying the menu:
<ol class="some-menu">
<li>Text</li>
<li>Text</li>
<li><a href="http://url_abc#"> Hyper Text 1</a></li>
<li><a href="http://url_def#"> Hyper Text 2</a></li>
<li>Text</li>
</ol>
... you can select the specific element with CSS based on that element's attribute value:
ol.some-menu li a[href*="url_def"] {
outline: 5px solid red;
}
This selector selects all <a>
elements that have a href
value containing url_def
- that are also inside <li>
s, which are inside <ul class="some-menu">
elements.
Working example: https://codepen.io/anon/pen/jxWmxR.
Attribute selectors do have a few modi operandi available and are well described here: MDN web docs.