2016-05-25 24 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

啊,現在已經很完美了!謝謝! –