CSS :nth-of-type(n) 選擇器的作用


使用 CSS :nth-of-type(n) 選擇器可為其父元素的第 n 個 <p> 元素設定樣式。你可以嘗試執行以下程式碼來實現 :nth-of-type(n)選擇器

示例

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-of-type(2) {
            background: yellow;
         }
      </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>
   </body>
</html>

更新於: 2020 年 6 月 30 日

148 次瀏覽

開啟你的 職業 生涯

完成該課程即可獲得認證

開始
廣告
© . All rights reserved.