CSS Selector :nth-last-of-type(n)

Description

:nth-last-of-type(n) selects elements that are the nth from last child of their type(CSS3). The argument is the index of the element. The indexes start at 1.

Example


<!DOCTYPE HTML> 
<html> 
    <head>
        <style type="text/css"> 
        body > :nth-last-of-type(2) { 
            border: thin black solid; 
            padding: 4px; 
        } <!-- w  ww.  j ava 2  s .  c o m-->
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
    </body> 
</html>

Click to view the demo

The code above generates the following result.

:nth-last-of-type(n)




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference