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


使用 CSS :only-of-type 選擇器,可為其父元素的唯一 <p> 元素設定樣式。

示例

您可嘗試執行以下程式碼,以實現 :only-of-type 選擇器

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:only-of-type {
            background: orange;
            color: white;
         }
      </style>
   </head>
   <body>
      <div>
         <p>This is demo text 1.</p>
      </div>
      <div>
         <p>This is demo text 2.</p>
         <p>This is demo text 3.</p>
         <p>This is demo text 4.</p>
      </div>
   </body>
</html>

更新時間:01-7 月-2020

97 次觀看

啟動您的 職業生涯

完成課程,獲得認證

開始學習
廣告