CSS Tutorial

CSS Style

CSS Layout Style

CSS Float Style

CSS Reference

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


What is :nth-last-of-type(n) Selector?

CSS :nth-last-of-type(n) selector matches nth last number sibling of its type and whose are child elements of an parent element.

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 4+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.

Syntax

General syntax of :nth-last-of-type selector,

element:nth-last-of-type(n) {
	property: value;
	property: value;
	...
}

/* match nth last number sibling of its type child element */
*:nth-last-of-type(n) {
	property: value;
	property: value;
	...
}

Example:

CSS :nth-last-of-type(1) selector select all 2nd sibling of its type child element.

<style type="text/css">
div :nth-last-of-type(1) {   /* div *:nth-last-of-type(1) */
	background:#ff0000;
}
</style>
</head>
<body>
    <div>
        <span>This is first span</span>
        <span>This is second span</span>
        <ul>
            <li>This is first line</li>
            <li>This is second line</li>
        </ul>
         <ul>
            <li>This is first line</li>
            <li>This is second line</li>
        </ul>       
        <p>First Paragraph</p>
        <p>Second Paragraph</p>	
    </div>
</body>

Run it...   »

Example Result: