CSS 条件规则模块第 3 级

W3C 候选推荐草案,

关于此文档的更多细节
此版本
https://w3org.cn/TR/2024/CRD-css-conditional-3-20240815/
最新发布版本
https://w3org.cn/TR/css-conditional-3/
编辑草案
https://drafts.csswg.org/css-conditional-3/
历史版本
历史
https://w3org.cn/standards/history/css-conditional-3/
实现报告
https://wpt.fyi/results/css/css-conditional?label=master&label=experimental&aligned
反馈
CSS 工作组问题仓库
编辑
L. David Baron (Mozilla)
Elika J. Etemad / fantasai (Apple)
Chris Lilley (W3C)
建议编辑此规范
GitHub 编辑器
测试套件
https://wpt.fyi/results/css/css-conditional/

摘要

This module contains the features of CSS for conditional processing of parts of style sheets, conditioned on capabilities of the processor or the document the style sheet is being applied to. It includes and extends the functionality of CSS level 2 [CSS21], which builds on CSS level 1 [CSS1]. The main extensions compared to level 2 are allowing nesting of certain at-rules inside @media, and the addition of the @supports rule for conditional processing.

CSS 是一种用于描述结构化文档(如 HTML 和 XML)在屏幕、纸张等介质上渲染方式的语言。

关于本文档

本部分描述了本文档在发布时的状态。当前 W3C 出版物列表及本技术报告的最新版本可在 W3C 技术报告索引(https://w3org.cn/TR/)中找到。

本文档由 CSS 工作组候选推荐标准草案的形式发布,遵循 推荐标准轨道。作为候选推荐标准发布并不意味着 W3C 及其成员的认可。候选推荐标准草案整合了前一个候选推荐标准中的变更,工作组打算将其包含在随后的候选推荐标准快照中。

这是一份草案文档,可能会随时被其他文档更新、替换或废弃。将其作为非进行中工作引用是不恰当的。

请通过 在 GitHub 上提交 issue(推荐)发送反馈,并在标题中包含规范代码 “css-conditional”,例如:“[css-conditional] …评论摘要…”。所有 issue 和评论均已 存档。或者,也可以将反馈发送至(已存档的)公共邮件列表 www-style@w3.org

本文档受 2023 年 11 月 3 日版 W3C 流程文档管辖。

本文档由在一个受 W3C 专利政策约束下运作的团体编写。W3C 维护着一份与该团体交付成果相关的专利披露公开列表;该页面还包含了披露专利的说明。任何知晓其认为包含 必要权利要求 (Essential Claim(s)) 的个人,必须根据 W3C 专利政策第 6 节披露相关信息。

以下功能存在风险,可能会在 CR 期间被删除:

“风险(At-risk)”是 W3C 流程中的术语,并不一定意味着该特性面临被删除或推迟的危险。这表示工作组认为该特性可能难以及时实现互操作,将其标记为此类允许工作组在转向“建议推荐标准(Proposed Rec)”阶段时,在必要的情况下删除该特性,而无需先发布一个不包含该特性的新“候选推荐标准(Candidate Rec)”。

1. 引言

1.1. 背景

本节不具有规范性。

[CSS21] 定义了一种条件分组规则——@media 规则,并且只允许在其中包含样式规则(不允许其他 @-规则)。@media 规则提供了根据媒体构建特定样式表的能力,这同样可以通过诸如 @importlink 等样式表链接特性实现。对 @media 规则内容的限制使其用途受限;这迫使使用涉及 @-规则的 CSS 功能的作者在媒体特定的样式表中必须为每种介质使用单独的样式表。

This specification extends the rules for the contents of conditional group rules to allow other @-rules, which enables authors to combine CSS features involving @-rules with media specific style sheets within a single style sheet.

This specification also defines an additional type of conditional group rule, @supports, to address author and user requirements.

The @supports rule allows CSS to be conditioned on implementation support for CSS properties and values. This rule makes it much easier for authors to use new CSS features and provide good fallback for implementations that do not support those features. This is particularly important for CSS features that provide new layout mechanisms, and for other cases where a set of related styles needs to be conditioned on property support.

1.2. 模块交互

This module replaces and extends the @media rule feature defined in [CSS21] section 7.2.1 and incorporates the modifications previously made non-normatively by [MEDIAQUERIES-4] section 1.

2. 条件分组规则的处理

This specification defines some CSS at-rules, called conditional group rules, that associate a condition with a group of other CSS rules. These different rules allow testing different types of conditions, but share common behavior for how their contents are used when the condition is true and when the condition is false.

例如,下面的规则
@media print {
  /* hide navigation controls when printing */
  #navigation { display: none }
}

仅在样式表用于打印介质时才会使特定的 CSS 规则(把 ID 为 “navigation” 的元素设为 display:none)生效。

每个条件分组规则都有一个条件,该条件随时会求值为 true 或 false。当条件为真时,CSS 处理器 必须 将组规则内部的规则视作位于组规则所在位置一样应用;当条件为假时,CSS 处理器 必须不 应用组规则内部的任何规则。条件的当前状态并不影响 CSS 对象模型,组规则的内容始终保留在组规则内部。

测试

If condition is true, rules applied in place.


If condition is false, rules not applied.


CSSOM contains rules regardless of condition.


This means that when multiple conditional group rules are nested, a rule inside of both of them applies only when all of the rules' conditions are true.

测试

Nested rules apply when all conditions are true.


例如,下面这组嵌套规则
@media print { /* rule (1) */
  /* hide navigation controls when printing */
  #navigation { display: none }
  @media (max-width: 12cm) { /* rule (2) */
    /* keep notes in flow when printing to narrow pages */
    .note { float: none }
  }
}

标记 (1) 的规则在打印介质时条件为真,标记 (2) 的规则在显示区域宽度(对打印介质而言为页面盒) ≤ 12 cm 时条件为真。因此,规则 #navigation { display: none } 在样式表被用于打印介质时始终生效,而规则 .note { float: none } 仅在样式表用于打印介质 页面盒宽度 ≤ 12 cm 时才生效。

When the condition for a conditional group rule changes, CSS processors must reflect that the rules now apply or no longer apply, except for properties whose definitions define effects of computed values that persist past the lifetime of that value (such as for some properties in [CSS3-TRANSITIONS] and [CSS3-ANIMATIONS]).

测试

Change in condition simultaneous with change in condition application (except per transition/animation rules).


3. 条件分组规则的内容

All conditional group rules are defined to take a <rule-list> in their block, and accept any rule that is normally allowed at the top-level of a stylesheet, and not otherwise restricted. (For example, an @import rule must appear at the actual beginning of a stylesheet, and so is not valid inside of another rule.)

测试

Valid to nest all unrestricted top-level rules.


Invalid or unknown rules inside the <rule-list> must be considered invalid and ignored, but do not invalidate the conditional group rule.

测试

Invalid rules do not invalidate conditional group rule.


Any namespace prefixes used in a conditional group rule must have been declared, otherwise they are invalid.

例如,下面的规则使用了 CSS 合格名称,是合法的,因为相应的 命名空间前缀 已经绑定到命名空间 URL。
@namespace x url(https://w3org.cn/1999/xlink);
@supports (content: attr(x|href)) {
  // do something }
例如,判断下面规则是否合法时
@supports (content: attr(n|tooltip)) {
  // do something }

用户代理会查询命名空间映射,查看是否存在与前缀 “n” 对应的命名空间 URL。

测试

Validity of namespace prefixes depends on namespace map.


4. 条件分组规则的位置

Conditional group rules are allowed wherever style rules are allowed (at the top-level of a style sheet, as well as within other conditional group rules). CSS processors must process such rules as described above.

测试

Conditional group rules allowed wherever style rules are allowed.


Any at-rules that are not allowed after a style rule (e.g., @charset, @import, or @namespace rules) are also not allowed after a conditional group rule, and are therefore invalid when so placed.

测试

At rules not allowed after style rule invalid after conditional group rule.


5. 特定媒体样式表:@media 规则

The @media rule is a conditional group rule whose condition is a media query. Its syntax is

@media <media-query-list> {
  <rule-list>
}

It consists of the at-keyword @media followed by a (possibly empty) media query list (as defined in [MEDIAQUERIES-4]), followed by a block containing arbitrary rules. The condition of the rule is the result of the media query.

This @media rule
@media screen and (min-width: 35em),
       print and (min-width: 40em) {
  #section_navigation { float: left; width: 10em; }
}

has the condition screen and (min-width: 35em), print and (min-width: 40em), which is true for screen displays whose viewport is at least 35 times the initial font size and for print displays whose viewport is at least 40 times the initial font size. When either of these is true, the condition of the rule is true, and the rule #section_navigation { float: left; width: 10em; } is applied.

测试

Media rule condition can be empty


Media rule condition is media query


White space is optional where not required for tokenization.


6. 特性查询:@supports 规则

The @supports rule is a conditional group rule whose condition tests whether the user agent supports CSS property:value pairs. Authors can use it to write style sheets that use new features when available but degrade gracefully when those features are not supported. These queries are called CSS feature queries or (colloquially) supports queries.

Note: CSS has existing mechanisms for graceful degradation, such as ignoring unsupported properties or values, but these are not always sufficient when large groups of styles need to be tied to the support for certain features, as is the case for use of new layout system features.

The syntax of the condition in the @supports rule is similar to that defined for <media-condition> in [MEDIAQUERIES-4], but without the "unknown" value logic

Therefore, the syntax of the @supports rule allows testing for property:value pairs, and arbitrary conjunctions (and), disjunctions (or), and negations (not) of them.

The syntax of the @supports rule is

@supports <supports-condition> {
  <rule-list>
}

with <supports-condition> defined as

<supports-condition> = not <supports-in-parens>
                     | <supports-in-parens> [ and <supports-in-parens> ]*
                     | <supports-in-parens> [ or <supports-in-parens> ]*
<supports-in-parens> = ( <supports-condition> ) | <supports-feature> | <general-enclosed>
<supports-feature> = <supports-decl>
<supports-decl> = ( <declaration> )

The above grammar is purposely very loose for forwards-compatibility reasons, since the <general-enclosed> production allows for substantial future extensibility. Any @supports rule that does not parse according to the grammar above (that is, a rule that does not match this loose grammar which includes the <general-enclosed> production) is invalid. Style sheets must not use such a rule and processors must ignore such a rule (including all of its contents).

测试

White space is optional where not required for tokenization.


Grammatically-invalid @supports rule is ignored.


Each of these grammar terms is associated with a boolean result, as follows

<supports-condition>
<supports-in-parens>

结果是子表达式的结果。

not <supports-in-parens>

结果是否定 <supports-in-parens> 项。

测试

Not 否定 supports 条件。


Not 必须后跟空格。


Not 需要括号。


<supports-in-parens> [ and <supports-in-parens> ]*

如果所有 <supports-in-parens> 子项都为 true,则结果为 true;否则为 false。

测试

And 条件为 true 当且仅当所有关联条件都为 true。


And 需要括号。


<supports-in-parens> [ or <supports-in-parens> ]*

如果所有 <supports-in-parens> 子项都为 false,则结果为 false;否则为 true。

测试

Or 条件为 true 当且仅当任意关联条件为 true。


Or 必须后跟空格。


Or 需要括号。


<supports-decl>

如果 UA supports 括号内的声明,则结果为 true。

测试

Supports 条件为 true 当且仅当声明被支持。


声明不能包含分号。


声明值可以为空。


声明不能包含无效的 !tokens。


<general-enclosed>

结果为 false。

作者不得在其样式表中使用 <general-enclosed>它仅用于未来兼容,以便新语法的加入不会使旧 UA 中的大量 <supports-condition> 失效。

测试

未被识别但语法合法的条件返回 false,而不是无效。


括号必须配平。


@supports 规则的条件是其前导部分中 <supports-condition> 计算的结果。

例如,下面的规则
@supports ( display: flex ) {
  body, #navigation, #content { display: flex; }
  #navigation { background: blue; color: white; }
  #article { background: white; color: black; }
}

仅在 @supports 规则的 display: flex 被支持时,才会应用其内部规则。

以下示例展示了一个额外的 @supports 规则,用于在 display: flex 不被支持时提供替代方案。
@supports not ( display: flex ) {
  body { width: 100%; height: 100%; background: white; color: black; }
  #navigation { width: 25%; }
  #article { width: 75%; }
}

请注意,width 声明可能会对基于 flex 的布局产生负面影响,因此应仅在非 flex 样式中出现。

以下示例检查对 box-shadow 属性的支持,包括对其厂商前缀版本的支持。如果支持,则同时指定 box-shadow(含前缀)和 border,从而在不支持 box-shadow 时使盒子不可见。
.noticebox {
  border: 1px solid black;
  padding: 1px;
}
@supports ( box-shadow: 0 0 2px black inset ) or
          ( -moz-box-shadow: 0 0 2px black inset ) or
          ( -webkit-box-shadow: 0 0 2px black inset ) or
          ( -o-box-shadow: 0 0 2px black inset ) {
  .noticebox {
    -moz-box-shadow: 0 0 2px black inset;
    -webkit-box-shadow: 0 0 2px black inset;
    -o-box-shadow: 0 0 2px black inset;
    box-shadow: 0 0 2px black inset; /* unprefixed last */
    /* override the rule above the @supports rule */
    border: none;
    padding: 2px;
  }
}

为避免将 andor 混淆,语法要求必须显式指定 both andor(而不是使用逗号或空格代替其中之一)。同样,为避免运算符优先级导致的歧义,语法不允许在没有括号层的情况下混用 andornot

例如,下面的规则是无效的
@supports (transition-property: color) or
          (animation-name: foo) and
          (transform: rotate(10deg)) {
  /* ... */
}

相反,作者必须写成以下任意一种形式

@supports ((transition-property: color) or
           (animation-name: foo)) and
          (transform: rotate(10deg)) {
  /* ... */
}
@supports (transition-property: color) or
          ((animation-name: foo) and
           (transform: rotate(10deg))) {
  /* ... */
}
测试

混合运算符时必须使用括号。


当声明是表达式中唯一内容时,必须始终把被测试的声明放在括号内。

例如,下面的规则是无效的
@supports display: flex {
  /* ... */
}

相反,作者必须写成

@supports (display: flex) {
  /* ... */
}
测试

在声明测试周围必须使用括号。


语法允许在不需要时使用额外的括号。这种灵活性有时方便作者(例如在注释掉表达式的某部分时),也可能对作者工具有用。

例如,作者可以写成
@supports ((display: flex)) {
  /* ... */
}
测试

允许使用额外的括号。


对被测试的声明使用尾部 !important 是允许的,不过它不会改变声明的有效性。

例如,下面的规则是有效的
@supports (display: flex !important) {
  /* ... */
}
测试

!important 是允许的。


6.1. Definition of support

为了向前兼容,CSS 2.1(第 4.1.8 节:声明和属性) [CSS21] 定义了处理无效属性和值的规则。未实现或仅部分实现某规范的 CSS 处理器必须把任何它们未实现或未提供可用支持级别的值部分视为无效,并因此必须将该声明视为解析错误而舍弃。

支持 某声明(即属性和值的组合)时,CSS 处理器在 样式规则 中接受该声明(而不是把它当作解析错误舍弃)。如果处理器对属性与值均未实现或未提供可用支持,则不得接受该声明或声称对其有支持。

注: 需要注意的是,用户偏好导致的属性或值实际被禁用的情况仍然在本定义中视为“支持”。例如,当用户启用了高对比度模式导致颜色被覆盖时,CSS 处理器仍然被视为支持 color 属性,即使 color 声明可能不起作用。另一方面,面向开发者的偏好(旨在启用或禁用对实验性 CSS 特性的支持)会影响本“支持”的定义。

这些规则(及其等价性)使作者能够使用回退(在 [CSS1] 中指被后面声明覆盖的声明,或本规范中 @supports 规则提供的新功能),从而在实现的特性上正确工作。尤其是对复合值的回退;实现必须实现值的全部组成部分,才能认为该声明在样式规则或在 @supports 规则的声明条件中被支持。

测试

支持查询为 true 当且仅当属性声明(包括全部值)能够被解析/支持。


7. APIs

测试

7.1. Extensions to the CSSRule interface

The CSSRule interface is extended as follows

partial interface CSSRule {
    const unsigned short SUPPORTS_RULE = 12;
};
测试

CSSRule.SUPPORTS_RULE = 12


7.2. The CSSConditionRule interface

The CSSConditionRule interface represents all the “conditional” at-rules, which consist of a condition and a statement block.

[Exposed=Window]
interface CSSConditionRule : CSSGroupingRule {
    readonly attribute CSSOMString conditionText;
};
测试

CSSConditionRule inherits from CSSGroupingRule.


CSSConditionRule has .conditionText attribute.


conditionText of type CSSOMString
The conditionText attribute represents the condition of the rule. Since what this condition does varies between the derived interfaces of CSSConditionRule, those derived interfaces may specify different behavior for this attribute (see, for example, CSSMediaRule below). In the absence of such rule-specific behavior, the following rules apply

The conditionText attribute, on getting, must return the result of serializing the associated condition.

测试

.conditionText returns serialization of condition.


    7.3. The CSSMediaRule interface

    The CSSMediaRule interface represents a @media at-rule

    [Exposed=Window]
    interface CSSMediaRule : CSSConditionRule {
        [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
        readonly attribute boolean matches;
    };
    
    media of type MediaList, readonly
    The media attribute must return a MediaList object for the list of media queries specified with the @media at-rule.
    测试

    .media returns a MediaList matching the @media condition.


      matches of type boolean, readonly
      The matches attribute returns true if the rule is in an stylesheet attached to a document whose Window matches this rule’s media media query, and returns false otherwise.
      测试

      .matches matches the media query, returns boolean.


        conditionText of type CSSOMString (CSSMediaRule-specific definition for attribute on CSSConditionRule)
        The conditionText attribute (defined on the CSSConditionRule parent rule), on getting, must return the value of media.mediaText on the rule.
        测试

        Value of CSSMediaRule.conditionText matches value of media.mediaText.


          7.4. The CSSSupportsRule interface

          The CSSSupportsRule interface represents a @supports rule.

          [Exposed=Window]
          interface CSSSupportsRule : CSSConditionRule {
            readonly attribute boolean matches;
          };
          
          matches of type boolean, readonly
          The matches attribute returns the evaluation of the CSS feature query represented in conditionText.
          测试

          CSSSupportsRule.matches returns true if matches feature query


            conditionText of type CSSOMString (CSSSupportsRule-specific definition for attribute on CSSConditionRule)
            The conditionText attribute (defined on the CSSConditionRule parent rule), on getting, must return the condition that was specified, without any logical simplifications, so that the returned condition will evaluate to the same result as the specified condition in any conformant implementation of this specification (including implementations that implement future extensions allowed by the <general-enclosed> extensibility mechanism in this specification). In other words, token stream simplifications are allowed (such as reducing whitespace to a single space or omitting it in cases where it is known to be optional), but logical simplifications (such as removal of unneeded parentheses, or simplification based on evaluating results) are not allowed.
            测试

            CSSSupportsRule.conditionText 可以进行标记流简化。


              CSSSupportsRule.conditionText 不能进行逻辑简化。


                7.5. The CSS namespace, and the supports() function

                The CSS namespace holds useful CSS-related functions that do not belong elsewhere.

                partial namespace CSS {
                  boolean supports(CSSOMString property, CSSOMString value);
                  boolean supports(CSSOMString conditionText);
                };
                
                supports(CSSOMString property, CSSOMString value), returns boolean
                When the supports(property, value) method is invoked with two arguments property and value
                1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports, or is a custom property name string, and value successfully parses according to that property’s grammar, return true.

                2. Otherwise, return false.

                Note: No CSS escape or whitespace processing is performed on the property name, so CSS.supports(" width", "5px") will return false, as " width" isn’t the name of any property due to the leading space.

                Note: !important flags are not part of property grammars, and will cause value to parse as invalid, just as they would in the value argument to element.style.setProperty().

                测试

                CSS.supports(arg1, arg2) evaluates support of property arg1 with value arg2.


                  supports(CSSOMString conditionText), returns boolean
                  When the supports(conditionText) method is invoked with a single conditionText argument
                  1. If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.

                  2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.

                  3. Otherwise, return false.

                  All namespaces in the conditionText argument are considered invalid, just as they are in document.querySelector("a|b").

                  测试

                  CSS.supports(arg1) evaluates supports condition arg1.


                    CSS.supports(arg1) implies parentheses.


                    测试

                    安全考量

                    This spec introduces no new security considerations.

                    隐私考量

                    本规范中的各种特性,主要与 @media 规则关联,但在一定程度上也与 @supports 规则关联,向 Web 内容提供用户的硬件、软件以及它们的配置和状态信息。大多数信息是通过 [MEDIAQUERIES-4] 中的特性提供的,而不是通过本规范中的特性。然而,@supports 规则可能会提供一些关于用户软件的额外细节,以及它是否在非默认设置下运行,从而启用或禁用某些特性。

                    大多数这些信息也可以通过其他 API 获取。然而,本规范中的特性是这些信息在 Web 上暴露的方式之一。

                    从聚合的角度看,这些信息也可用于提高用户 指纹识别 的准确性。

                    8. 变更记录

                    2022 年 1 月 13 日候选推荐快照 以来,对本规范所做的以下(非编辑性)更改

                    2020 年 12 月 8 日候选推荐快照 以来,对本规范所做的以下(非编辑性)更改

                    2013 年 4 月 4 日候选推荐 以来,对本规范所做的以下(非编辑性)更改

                    致谢

                    感谢 Tab Atkins、Arthur Barstow、Ben Callahan、Tantek Çelik、Alex Danilo、Elika Etemad、Pascal Germroth、Björn Höhrmann、Paul Irish、Brad Kemper、Anne van Kesteren、Vitor Menezes、Alex Mogilevsky、Chris Moschini、James Nurthen、Simon Pieters、Florian RivoalSimon Sapin、Nicholas Shanks、Ben Ward、Zack Weinberg、Estelle Weyl、Boris Zbarsky 以及 www-style 社区的所有其他成员提供的想法和反馈。

                    一致性

                    文档约定

                    一致性要求通过描述性断言和 RFC 2119 术语相结合来表达。本文档规范性部分中的关键词“MUST”(必须)、“MUST NOT”(不得)、“REQUIRED”(必需)、“SHALL”(应)、“SHALL NOT”(不应)、“SHOULD”(推荐)、“SHOULD NOT”(不推荐)、“RECOMMENDED”(建议)、“MAY”(可以)和“OPTIONAL”(可选)应按照 RFC 2119 中的描述进行解释。然而,为了可读性,这些词在本文档中不以全大写形式出现。

                    本规范的所有文本均为规范性文本,明确标记为非规范性的部分、示例和注释除外。 [RFC2119]

                    本规范中的示例均以“例如”开头,或使用 class="example" 与规范性文本隔开,如下所示

                    这是一个说明性示例。

                    提示性说明以“Note”开头,并使用 class="note" 与规范性文本隔开,如下所示

                    注意,这是一个说明性注释。

                    建议(Advisements)是旨在引起特别注意的规范性部分,并使用 <strong class="advisement"> 与其他规范性文本隔开,如下所示: UA 必须提供可访问的替代方案。

                    测试

                    与本规范内容相关的测试可记录在“Tests”块中,就像这一个一样。任何此类块都是非规范性的。


                    一致性类别

                    本规范为三类一致性定义了一致性要求。

                    样式表
                    一份 CSS 样式表
                    渲染器
                    一种 用户代理 (UA),它解释样式表的语义并渲染使用它们的文档。
                    创作工具
                    一种 用户代理 (UA),用于编写样式表。

                    如果样式表包含的所有使用本模块定义语法的语句,根据通用 CSS 语法及本模块定义的各功能语法均有效,则该样式表符合本规范。

                    如果渲染器除了按相应规范解释样式表外,还通过正确解析本规范定义的所有功能并相应地渲染文档来支持这些功能,则该渲染器符合本规范。然而,由于设备限制导致 UA 无法正确渲染文档,并不意味着该 UA 不符合规范。(例如,UA 无需在单色显示器上渲染颜色。)

                    如果创作工具编写的样式表根据通用 CSS 语法及本模块中各功能的语法是句法正确的,并符合本模块中描述的所有其他样式表一致性要求,则该创作工具符合本规范。

                    部分实现

                    为了使作者能够利用前向兼容的解析规则来指定后备值,CSS 渲染器 **必须** 将其无法使用支持级别的任何 @规则、属性、属性值、关键字和其他语法结构视为无效(并 适当忽略)。特别地,用户代理 **不得** 在单一多值属性声明中选择性地忽略不支持的组件值而保留支持的值:如果任何值被视为无效(因为不支持的值必须如此),CSS 要求忽略整个声明。

                    不稳定和专有特性的实现

                    为了避免与未来稳定的 CSS 功能发生冲突,CSS 工作组建议在实施不稳定功能和私有扩展遵循最佳实践

                    非实验性实现

                    一旦规范达到候选推荐阶段,非实验性实现即可成为可能,实现者应发布他们能够证明根据规范正确实现的任何 CR 级别特性的无前缀实现。

                    为建立并保持 CSS 在不同实现间的互操作性,CSS 工作组请求非实验性的 CSS 渲染器在发布任何 CSS 功能的无前缀实现之前,向 W3C 提交一份实现报告(并在必要时提交用于该实现报告的测试用例)。提交给 W3C 的测试用例需经 CSS 工作组审阅和修正。

                    有关提交测试用例和实现报告的详细信息,请访问 CSS 工作组网站 https://w3org.cn/Style/CSS/Test/。问题可发送至 public-css-testsuite@w3.org 邮件列表。

                    候选推荐标准 (CR) 退出标准

                    为了使本规范能够推进到提案推荐标准 (PR),必须至少有两个独立的、可互操作的每个功能的实现。每个功能可以由不同组的产品实现,不要求所有功能都由单个产品实现。为了实现此标准,我们定义以下术语

                    independent
                    每个实现必须由不同的方开发,并且不能共享、重用或派生自另一个合格实现所使用的代码。对本规范实现无影响的代码段不受此要求限制。
                    可互操作
                    通过官方 CSS 测试套件中的相应测试用例,或者如果实现不是 Web 浏览器,则通过等效测试。如果此类用户代理 (UA) 用于声明互操作性,则测试套件中的每个相关测试都应创建等效测试。此外,如果此类 UA 用于声明互操作性,则必须有一个或多个额外的 UA,它们也可以以相同的方式通过这些等效测试,以实现互操作性的目的。等效测试必须公开,以供同行评审。
                    实现
                    用户代理,即
                    1. 实现了该规范。
                    2. 对公众可用。该实现可以是出货产品或其他公开可用的版本(即测试版、预览发布版或“每日构建版”)。非出货产品发布版必须已实现该功能至少一个月,以证明其稳定性。
                    3. 不是实验性的(即,专门为通过测试套件设计且不打算用于正常使用的版本)。

                    该规范将保持候选推荐标准状态至少六个月。

                    索引

                    本规范定义的术语

                    通过引用定义的术语

                    引用

                    规范性引用

                    [CSS-CASCADE-5]
                    Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. CSS Cascading and Inheritance Level 5. 2022年1月13日. CR. URL: https://w3org.cn/TR/css-cascade-5/
                    [CSS-NAMESPACES-3]
                    Elika Etemad. CSS 命名空间模块 Level 3。2014 年 3 月 20 日。REC。URL: https://w3org.cn/TR/css-namespaces-3/
                    [CSS-SYNTAX-3]
                    Tab Atkins Jr.; Simon Sapin. CSS Syntax Module Level 3. 2021年12月24日. CR. URL: https://w3org.cn/TR/css-syntax-3/
                    [CSS-TYPED-OM-1]
                    Tab Atkins Jr.; François Remy. CSS Typed OM 第 1 级. 2024年3月21日. WD. URL: https://w3org.cn/TR/css-typed-om-1/
                    [CSS-VALUES-4]
                    Tab Atkins Jr.; Elika Etemad. CSS 值与单位模块 4 级 (CSS Values and Units Module Level 4). 2024年3月12日. WD. URL: https://w3org.cn/TR/css-values-4/
                    [CSS21]
                    Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 2011年6月7日. REC. URL: https://w3org.cn/TR/CSS21/
                    [CSS3-ANIMATIONS]
                    David Baron; et al. CSS Animations Level 1. 2023年3月2日. WD. URL: https://w3org.cn/TR/css-animations-1/
                    [CSSOM-1]
                    Daniel Glazman; Emilio Cobos Álvarez. CSS Object Model (CSSOM). 2021年8月26日. WD. URL: https://w3org.cn/TR/cssom-1/
                    [HTML]
                    Anne van Kesteren; et al. HTML 标准. Living Standard. URL: https://html.whatwg.cn/multipage/
                    [INFRA]
                    Anne van Kesteren; Domenic Denicola. Infra 标准. Living Standard. URL: https://infra.spec.whatwg.org/
                    [MEDIAQUERIES-4]
                    Florian Rivoal; Tab Atkins Jr.. Media Queries Level 4. 2021年12月25日. CR. URL: https://w3org.cn/TR/mediaqueries-4/
                    [MEDIAQUERIES-5]
                    Dean Jackson; 等人. Media Queries Level 5. 2021年12月18日. WD. URL: https://w3org.cn/TR/mediaqueries-5/
                    [RFC2119]
                    S. Bradner. RFC 中用于指示要求级别的关键词. 1997年3月. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
                    [WEBIDL]
                    Edgar Chen; Timothy Gu. Web IDL 标准. Living Standard. URL: https://webidl.spec.whatwg.org/

                    参考资料

                    [CSS-BACKGROUNDS-3]
                    Elika Etemad; Brad Kemper. CSS 背景与边框模块 Level 3. 2024年3月11日. CR. URL: https://w3org.cn/TR/css-backgrounds-3/
                    [CSS-COLOR-4]
                    Chris Lilley; Tab Atkins Jr.; Lea Verou. CSS 颜色模块第 4 级. 2024年2月13日. CR. URL: https://w3org.cn/TR/css-color-4/
                    [CSS-DISPLAY-3]
                    Elika Etemad; Tab Atkins Jr.. CSS Display Module Level 3. 2023年3月30日. CR. URL: https://w3org.cn/TR/css-display-3/
                    [CSS-SIZING-3]
                    Tab Atkins Jr.; Elika Etemad. CSS Box Sizing Module Level 3. 2021年12月17日. WD. URL: https://w3org.cn/TR/css-sizing-3/
                    [CSS1]
                    Håkon Wium Lie; Bert Bos. 层叠样式表,Level 1. 2018 年 9 月 13 日. REC. URL: https://w3org.cn/TR/CSS1/
                    [CSS3-TRANSITIONS]
                    David Baron; et al. CSS Transitions. 2018年10月11日. WD. URL: https://w3org.cn/TR/css-transitions-1/

                    IDL 索引

                    partial interface CSSRule {
                        const unsigned short SUPPORTS_RULE = 12;
                    };
                    
                    [Exposed=Window]
                    interface CSSConditionRule : CSSGroupingRule {
                        readonly attribute CSSOMString conditionText;
                    };
                    
                    [Exposed=Window]
                    interface CSSMediaRule : CSSConditionRule {
                        [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
                        readonly attribute boolean matches;
                    };
                    
                    [Exposed=Window]
                    interface CSSSupportsRule : CSSConditionRule {
                      readonly attribute boolean matches;
                    };
                    
                    partial namespace CSS {
                      boolean supports(CSSOMString property, CSSOMString value);
                      boolean supports(CSSOMString conditionText);
                    };