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

CSS Child Selector (>)


เลือกเฉพาะลูกโดยตรง

ใช้ div > p เพื่อเลือก <p> ที่เป็นลูกโดยตรงของ <div> ไม่รวมหลาน

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    div > p {
      background-color: orange;
    }
  </style>
</head>
<body>
  <div>
    <p>Para 1 in the div.</p>
    <!-- This is not a Child -->
    <span><p>Para 2 in the div.</p></span>
  </div>
  <p>Para 3 outside the div.</p>
</body>
</html>