:nth-child(n) सेलेक्टर का उपयोग
:nth-child(n) सेलेक्टर पैरेंट के **सभी चाइल्ड्स** (किसी भी टाइप के) में से nth चाइल्ड को सिलेक्ट करता है, लेकिन केवल तभी जब वह निर्दिष्ट टाइप का हो (यहां p)।
उदाहरण
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-child(4) {
background: orange;
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>
<p>This is demo text 6.</p>
</body>
</html>
यहां 4th चाइल्ड (जो <p> भी है) स्टाइल होगा। यदि 4th चाइल्ड <div> होता, तो कोई <p> स्टाइल नहीं होता।