使用 CSS 設定未指定元素的所有元素的樣式


要設定未指定元素的所有元素的樣式,請使用 CSS :not(selector) 選擇器。

示例

你可以嘗試執行以下程式碼來實現 :not 選擇器

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p {
            color: red;
         }
         :not(p) {
            color: blue;
         }
      </style>
   </head>
   <body>
      <h1>Heading 1</h1>
      <h2>Heading 2</h2>
      <h3>Heading 3</h3>
      <p>This is a paragraph.</p>
      <p>This is another paragraph.</p>
   </body>
</html>

更新於:01-Jul-2020

90 次瀏覽

開啟你的事業

完成課程即可獲得認證

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