gpt4 book ai didi

html - :not and text-decoration bug? 发送到哪里

转载 作者:行者123 更新时间:2023-11-28 04:30:25 25 4
gpt4 key购买 nike

我想我发现了 :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>

最佳答案

文本修饰被应用于 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 .

关于html - :not and text-decoration bug? 发送到哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com