大网数据广告活动
Web 标准与前端开发

CSS conditional rules

· 52CE 我爱测

The **CSS conditional rules** module defines CSS media and support queries, enabling you to define styles that are only applied if specific conditions are met. The conditional rules defined in this module are based on device, user-agent, and viewport capabilities. With conditiona

The CSS conditional rules module defines CSS media and support queries, enabling you to define styles that are only applied if specific conditions are met. The conditional rules defined in this module are based on device, user-agent, and viewport capabilities. With conditional rules, you can target CSS styles based on query values or browser and device features, independent of the document being rendered.

The first CSS conditional rules were media types specifying the intended destination medium for the linked styles, for example screen or print. These were set as the value of the HTML link and style elements' media attributes or as a comma-separated list of media types within an @import statement or at-rule. The ability to conditionally apply CSS rules has been greatly expanded since the CSS 2.1 and HTML 4.01 implementations that limited conditional queries to a few media types.

CSS conditional rules now include feature queries; the @supports at-rule enables targeting CSS styles based on a user-agent's CSS capabilities. Additional conditions include which selector, font-formats, and font-techs are supported.

The CSS conditional rules module also expands @media to enable nesting at-rules, with the related CSS media queries module removing unused media types and adding many media features and conditions that can be targeted.

The CSS container queries module defines similar conditional rules, but based on an element's parent rather than the viewport.

There are plans to further extend possible queries by adding the generalized conditional rule @when and the chained conditional rule @else. These two at-rules are not yet supported.

Reference

Properties

  • container
  • container-name
  • container-type

At-rules and descriptors

The CSS conditional rules module also introduces the @else and @when at-rules. Currently, no browsers support these features.

Functions

The CSS conditional rules module also introduces a media() CSS function. Currently, no browsers support this feature.

data types

Interfaces

  • CSSConditionRule
  • CSSMediaRule
  • CSSSupportsRule
  • CSS.supports_static method

Terms and glossary definitions

Guides

Related concepts

Specifications

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。