使用 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>

更新時間:2020 年 7 月 1 日

90 次瀏覽

開啟你的 職業生涯

完成課程後獲得認證

開始行動
廣告