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

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


Pseudo-class :first-of-type

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

ตัวอย่าง

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