2016-05-25 21 views
1

我想我找到了一个错误:不是选择器,我不知道在哪里提交CSS错误?:不是和文字装饰的bug?在哪里发送这

文本修饰将适用于该元素在:不

看到这个小codepen我已经放在一起,但是下划线是不是颜色正确应用。

https://codepen.io/miketricking/pen/YWKGyJ

p { 
 
    color: #000000; 
 
} 
 

 
:not(p) { 
 
    color: red; 
 
    text-decoration: underline; 
 
}
<h1>This is a heading</h1> 
 

 
<p>This is a paragraph.</p> 
 
<p>This is another paragraph.</p> 
 

 
<div>This is some text in a div element.</div>

+0

正如@BoltClock所说,样式是从'html'和'body'元素继承而来的,可以在浏览器开发工具中看到 - [见这里](http://s33.postimg.org/4e9ba8j4v/ Screen_Shot_2016_05_25_at_13_47_53.png) – Vucko

回答

7

文本修饰正在用的h1和DIV沿施加到身体和HTML,。所有四个元素匹配:not(p)。从身体的装饰正在传播到p元素,这就是为什么你看到一个红色的下划线(因为它的color: red声明是用来呈现下划线)。这不是任何浏览器中的错误或规范中的错误 - 相反,这是stated very deliberately in the spec

您可以通过将body添加到您的选择器来解决此问题,但它仅适用于顶级p元素,并且不会出现在与其他元素匹配的任何元素中:not(p)并传播其文本装饰:

p { 
 
    color: #000000; 
 
} 
 

 
body :not(p) { 
 
    color: red; 
 
    text-decoration: underline; 
 
}
<h1>This is a heading</h1> 
 

 
<p>This is a paragraph.</p> 
 
<p>This is another paragraph.</p> 
 

 
<div>This is some text in a div element.</div>

不幸的是,你不能阻止文本修饰传播到您的p元素没有在这个过程中改变他们的显示类型和破坏你的布局。请参阅this answer

+0

啊,现在已经很完美了!谢谢! –