CSS :last-of-type 選擇器的作用


使用 CSS :last-child 選擇器為其父元素的最後一個子元素的每個 <p> 元素設定樣式。

示例

您可以嘗試執行以下程式碼來實現 :last-child 選擇器 -

演示

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

更新於: 2020 年 6 月 30 日

99 次瀏覽

開啟 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.