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

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


Pseudo-class :last-child

ใช้ :last-child เพื่อเลือกองค์ประกอบ <p> ที่เป็นลูกสุดท้ายของพาเรนต์โดยตรง

ตัวอย่าง

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