html - 为什么是:not(p) seemingly selecting <p> tags?

标签 html css css-selectors

我的 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/

相关文章:

php - 第 n 个 child 调整图像缩略图和标题的大小

javascript - IE 10 不遵守 z-index

html - 如何让我的 Django 表单保存图像?

html - 是否可以只为 <p> 而不是 <a> 元素设置不透明度?

html - Firefox 中的折叠边距对齐

CSS 选择器 - 如何定位特定元素

python - 将 Python 文件中的 JSON 数据显示为 HTML

html - 使用 'ngx-pagination' 的默认样式未覆盖 Angular 样式 css

javascript - 为什么我的图像与我的其他图像 HTML 不对齐

CSS 在 <li> 中定位 <a> 标签