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

เลือกทุกองค์ประกอบ

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

ที่สองขององค์ประกอบหลัก นับจากลูกคนสุดท้าย


ใช้ตัวเลือก CSS :nth-last-of-type(n) เพื่อเลือกทุกองค์ประกอบ

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

ที่สองขององค์ประกอบหลัก โดยนับจากลูกสุดท้าย

ตัวอย่าง

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

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-last-of-type(2) {
            background: blue;
            color: white;
         }
      </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>
      <p>This is demo text 5.</p>
   </body>
</html>