樣式化作為其父元素的最後一個子元素的每個

元素


要樣式化作為其父元素的最後一個子元素的每個 <p> 元素,請使用 CSS :last-child 選擇器。你可以嘗試執行以下程式碼以實現 :last-child 選擇器

示例

動態示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:last-child {
            background: orange;
         }
      </style>
   </head>
   <body>
      <p>This is demo text1.</p>
      <p>This is demo text2.</p>
      <p>This is demo text3.</p>
   </body>
</html>

輸出

更新日期: 2020 年 6 月 22 日

109 次瀏覽

職業生涯起航

透過完成課程獲得認證

開始
廣告