:nth-of-type(n) सेलेक्टर का उपयोग
:nth-of-type(n) सेलेक्टर पैरेंट के अंदर अपने टाइप के nth एलिमेंट को सिलेक्ट करता है। यह केवल उसी टाइप के एलिमेंट्स गिनता है।
उदाहरण
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-of-type(2) {
background: yellow;
}
</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>
</body>
</html>
यहां दूसरा <p> पीला होगा। 2n (सम), 2n+1 (विषम), 3n (हर तीसरा) जैसे सूत्र भी उपयोग कर सकते हैं।