為每一個

元素設定樣式,該元素是其父級的子級,從最後一個子級開始計算


使用 CSS :nth-last-child(n) 選擇器為每一個是其父級的子級的 <p> 元素設定樣式,從最後一個子級開始計算。你可以嘗試執行以下程式碼來實現 :nth-last-child(n)選擇器

示例

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-last-child(4) {
            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>
      <p>This is demo text 6.</p>
   </body>
</html>

輸出

更新於: 22-Jun-2020

146 次瀏覽

開啟您的 職業生涯

完成課程以獲得認證

立即開始
廣告