:nth-last-of-type(n) सेलेक्टर का उपयोग
:nth-last-of-type(n) सेलेक्टर का उपयोग पैरेंट एलिमेंट के अंदर अंतिम बच्चे से गिनती करके nth टाइप के एलिमेंट को सिलेक्ट करने के लिए किया जाता है।
उदाहरण
नीचे दिए गए उदाहरण में, पैरेंट के अंदर अंतिम से दूसरा <p> एलिमेंट (यानी 5 पैराग्राफ में से 4th) को स्टाइल किया गया है।
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-last-of-type(2) {
background: blue;
color: white;
}
</style>
</head>
<body>
<p>This is demo text 1.</p>
<p>This is demo text 2.</p>
<p>This is demo text 3.</p>
<p>This is demo text 4.</p>
<p>This is demo text 5.</p>
</body>
</html>
नोट: यह सेलेक्टर केवल उसी टाइप के एलिमेंट्स को गिनता है (यहां <p>), अन्य टैग्स को नजरअंदाज करता है।