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>

更新於:30-Jun-2020

99 次瀏覽

開啟你的 職業生涯

完成本課程以獲得認證

立即開始
廣告
© . All rights reserved.