【问题标题】::not and text-decoration bug? Where to send this:not 和文本装饰错误?这个寄到哪里
【发布时间】:2016-05-25 19:56:10
【问题描述】:

我想我发现了 :not 选择器的错误,但我不确定在 CSS 中的哪里提交错误?

text-decoration 将应用于 :not 中的元素

查看我整理的这个小代码笔,颜色应用正确但下划线不正确。

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>

【问题讨论】:

  • 正如@BoltClock所说,样式继承自html和body元素,可以在浏览器开发者工具中看到-see here

标签: html css css-selectors


【解决方案1】:

文本修饰被应用于body和html,以及 h1和div。所有四个元素都匹配: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。

【讨论】:

  • 啊,这很有意义!谢谢!
猜你喜欢
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-11
  • 2016-09-29
  • 1970-01-01
  • 2022-01-24
相关资源
最近更新 更多