Vin*_*ias 21 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>
Run Code Online (Sandbox Code Playgroud)
我的stylsheet.css是这样的:
:not(p)
{
color:#ff0000;
}
Run Code Online (Sandbox Code Playgroud)
然而一切都是红色的,包括<p>.我尝试过Firefox 20,Internet Explorer 10和Chrome.它似乎没有比这更基本,但我无法弄清楚为什么这不起作用(防止<p>变红,即).任何有关这方面的帮助将非常感激.
Nie*_*sol 24
:not(p)比赛body.
默认color值为inherit.
p 没有风格设置.
p因此body,它继承了它的颜色,它是红色的.
解决方案:明确定义您想要变为红色的内容,或明确设置不同的颜色p(即不使用:not),或使用:not(body):not(p)