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

จัดรูปแบบทุกองค์ประกอบ

ที่เป็นองค์ประกอบที่ n

ขององค์ประกอบหลักด้วย CSS


ใช้ตัวเลือก CSS :nth-of-type(n) เพื่อจัดรูปแบบทุก ๆ

องค์ประกอบที่เป็นองค์ประกอบ nth

ของพาเรนต์ คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้ตัวเลือก :nth-of-type(n)

ตัวอย่าง

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