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


使用 CSS :first-of-type 選擇器為其父級的第一個 <p> 元素設定 CSS 樣式。

示例

你可以嘗試執行以下程式碼來實現 :first-of-type 選擇器

線上演示

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

更新於: 2020-06-30

112 次瀏覽

開啟你的 職業 生涯

完成課程後獲得認證

開始學習
廣告
© . All rights reserved.