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