gpt4 book ai didi

css - 分组 CSS 选择器 &::selection

转载 作者:行者123 更新时间:2023-12-01 13:56:30 30 4
gpt4 key购买 nike

为什么我们不能像这样对 CSS 进行分组

p::selection , p::-moz-selection 
{background:transparent;}

演示: http://jsfiddle.net/l2aelba/MRyVC/1/

为什么我们要像这样一一挑选

p::selection       {background:transparent;}
p::-moz-selection {background:transparent;}

演示: http://jsfiddle.net/l2aelba/MRyVC/

有人可以扩展这个问题吗?

最佳答案

浏览器是 expected如果选择器的任何部分无效,则删除整个规则:

The selector (see also the section on selectors) consists of everything up to (but not including) the first left curly brace ({). A selector always goes together with a declaration block. When a user agent cannot parse the selector (i.e., it is not valid CSS 2.1), it must ignore the selector and the following declaration block (if any) as well.

CSS 2.1 gives a special meaning to the comma (,) in selectors. However, since it is not known if the comma may acquire other meanings in future updates of CSS, the whole statement should be ignored if there is an error anywhere in the selector, even though the rest of the selector may look reasonable in CSS 2.1.

(请注意,就浏览器而言,“有效的 CSS 2.1”真正意味着“浏览器理解和支持的选择器”。)

由于非 Mozilla 浏览器不理解 ::-moz-selection,因此他们不得不放弃该规则。由于 Mozilla 浏览器不理解 ::selection,因此它们也必须放弃该规则。这是一个双输的局面(也是前缀难以使用的另一个原因,尤其是在选择器中)。

郑重声明,我很惊讶这在 Chrome 中不再有效(至少在 Windows 上的第 25 版中是这样,因为我刚刚测试过)。它曾经顽固地将选择器 p::selection, p::-moz-selection 解析为简单的 p::selection 并应用规则而不是遵循规范,并且开发商有理由这样做。我想知道发生了什么变化...

关于css - 分组 CSS 选择器 &::selection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15614022/

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