CSS :nth-last-child(n) 選擇器的應用


使用 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>

輸出

更新日期:2020-6-22

169 次瀏覽

開啟你的 職業 生涯

透過完成課程獲取證書

開始
廣告
© . All rights reserved.