Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

จัดสไตล์ p ตัวที่ n ของพาเรนต์ด้วย CSS


Pseudo-class :nth-of-type(n)

ใช้ :nth-of-type(n) เลือก <p> ตัวที่ n ของพาเรนต์ (นับเฉพาะ p)

ตัวอย่าง

<!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>