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

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


Pseudo-class :last-of-type

ใช้ :last-of-type เลือก <p> ตัวสุดท้ายของพาเรนต์ (นับเฉพาะ p)

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    p:last-of-type {
      background: orange;
    }
  </style>
</head>
<body>
  <h2>Heading</h2>
  <p>This is demo text1.</p>
  <p>This is demo text2.</p>
  <p>This is demo text3.</p>
</body>
</html>