我的 HTML 是这样的:
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="stylesheet.css">
<head>
</head>
<body>
<p>hiya</p>
<h1>this is h1</h1>
<h2>this is h2</h2>
</body>
</html>
我的 stylsheet.css 是这样的:
:not(p)
{
color:#ff0000;
}
然而一切都是红色的,包括<p>
.我试过 Firefox 20、Internet Explorer 10 和 Chrome。它似乎没有比这更基本的了,但我不明白为什么这不起作用(防止 <p>
变红,就是这样)。对此的任何帮助将不胜感激。
最佳答案
:not(p)
匹配 body
。
默认的color
值为inherit
。
p
没有设置样式。
p
因此从 body
继承了它的颜色,它是红色的。
解决方案:明确定义你想要红色的东西,或者为 p
明确设置不同的颜色(即不要使用 :not
),或者使用 :不(正文):不(p)
关于html - 为什么是:not(p) seemingly selecting <p> tags?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16028074/