At-rules - CSS: Cascading Style Sheets 编辑

At-rules are CSS statements that instructs CSS how to behave. They begin with an at sign, '@' (U+0040 COMMERCIAL AT), followed by an identifier and includes everything up to the next semicolon, ';' (U+003B SEMICOLON), or the next CSS block, whichever comes first.

Syntax

Regular

/* General structure */
@IDENTIFIER (RULE);

/* Example: tells browser to use UTF-8 character set */
@charset "utf-8";

There are several regular at-rules, designated by their identifiers, each with a different syntax:

  • @charset — Defines the character set used by the style sheet.
  • @import — Tells the CSS engine to include an external style sheet.
  • @namespace — Tells the CSS engine that all its content must be considered prefixed with an XML namespace.

Nested

@IDENTIFIER (RULE) {

}

A subset of nested statements, which can be used as a statement of a style sheet as well as inside of conditional group rules.

  • @media — A conditional group rule that will apply its content if the device meets the criteria of the condition defined using a media query.
  • @supports — A conditional group rule that will apply its content if the browser meets the criteria of the given condition.
  • @document This is an obsolete API and is no longer guaranteed to work. — A conditional group rule that will apply its content if the document in which the style sheet is applied meets the criteria of the given condition. (deferred to Level 4 of CSS Spec)
  • @page — Describes the aspect of layout changes that will be applied when printing the document.
  • @font-face — Describes the aspect of an external font to be downloaded.
  • @keyframes — Describes the aspect of intermediate steps in a CSS animation sequence.
  • @viewport This is an obsolete API and is no longer guaranteed to work. — Describes the aspects of the viewport for small screen devices. (currently at the Working Draft stage)
  • @counter-style — Defines specific counter styles that are not part of the predefined set of styles. (at the Candidate Recommendation stage, but only implemented in Gecko as of writing)
  • @font-feature-values (plus @swash, @ornaments, @annotation, @stylistic, @styleset and @character-variant) — Define common names in font-variant-alternates for feature activated differently in OpenType. (at the Candidate Recommendation stage, but only implemented in Gecko as of writing)
  • @property This is an experimental API that should not be used in production code. — Describes the aspect of custom properties and variables. (currently at the Working Draft stage)

Conditional group rules

Much like the values of properties, each at-rule has a different syntax. Nevertheless, several of them can be grouped into a special category named conditional group rules. These statements share a common syntax and each of them can include nested statements—either rulesets or nested at-rules. Furthermore, they all convey a common semantic meaning—they all link some type of condition, which at any time evaluates to either true or false. If the condition evaluates to true, then all of the statements within the group will be applied.

Conditional group rules are defined in CSS Conditionals Level 3 and are:

Since each conditional group may also contain nested statements, there may be an unspecified amount of nesting.

Index

CD
  • @document This is an obsolete API and is no longer guaranteed to work.
FIKMNP
  • @page
  • @property This is an experimental API that should not be used in production code.
SV
  • @viewport This is an obsolete API and is no longer guaranteed to work.

Specifications

SpecificationStatusComment
CSS Conditional Rules Module Level 3Candidate RecommendationInitial definition
Compatibility Standard
The definition of 'CSS At-rules' in that specification.
Living StandardStandardizes @-webkit-keyframes.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:103 次

字数:14003

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文