CSS :nth-last-of-type(n) 選擇器的作用


可以使用 CSS :nth-last-of-type(n) 選擇器選擇其父元素的第二個 <p> 元素(從最後一個子元素算起)。

示例

你可以嘗試執行以下程式碼來實現 :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>

更新日期:2020 年 6 月 21 日

115 次檢視

開啟你的職業生涯

完成課程以獲得認證

開始學習
廣告
© . All rights reserved.