@supports

この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

Summary

The @supports CSS at-rule associates a set of nested statements, in a CSS block, that is delimited by curly braces, with a condition consisting of testing of CSS declarations, that is property-value pairs, combined with arbitrary conjunctions, disjunctions, and negations of them. Such a condition is called a supports condition.

It allows to perform a feature query.

The @supports at-rule may be used not only at the top level of a CSS, but also inside any CSS conditional-group at-rule and can be accessed via the CSS object model interface CSSSupportsRule.

Syntax

@supports <supports_condition> {
  /* specific rules */
}

A supports condition consists of one or several declarations combined by different logical operators. Precedence of operators can be overruled by using parenthesis.

Declaration syntax

The simplest expression is a CSS declaration, that is a CSS property name followed by a value, separated by a colon. The following expression

( transform-origin: 5% 5% )

returns true if the transform-origin implements a syntax considering 5% 5% as valid.

A CSS declaration is always surrounded by parentheses.

The not operator

The not operator can precede any expression to create a new expression, resulting in the negation of the original expression. The following expression

not ( transform-origin: 10em 10em 10em )

returns true if transform-origin doesn't implement a syntax considering 10em 10em 10em as valid.

Like any operator, the not operator can be applied to a declaration of any complexity. The following examples are all valid expressions:

not ( not ( transform-origin: 2px ) )
(display: flexbox) and ( not (display: inline-grid) )

Note: there is no need to enclose the not operator between two parenthesis when at the top level. But to combine it with other operators, like and and or, the parenthesis are required.

The and operator

From two expressions, the and operator creates a new expression consisting in the conjunction of the two original ones, that is the resulting expression is true only if both of the original expressions also resolve to true. In this example, the complete expression resolves to true if and only if the two expressions are simultaneously true:

(display: table-cell) and (display: list-item)

Several conjunctions can be juxtaposed without the need of more parenthesis:

(display: table-cell) and (display: list-item) and (display:run-in)

is equivalent to:

(display: table-cell) and ((display: list-item) and (display:run-in))

The or operator

From two expressions, the or operator creates a new expression consisting in the disjunction of the two original ones, that is the resulting expression is true if one, or both, of the original expressions also resolves to true. In this example, the complete expression resolves to true if at least one of the two expressions is true:

( transform-style: preserve ) or ( -moz-transform-style: preserve )

Several disjunctions can be juxtaposed without the need of more parenthesis:

( transform-style: preserve ) or ( -moz-transform-style: preserve ) or 
( -o-transform-style: preserve ) or ( -webkit-transform-style: preserve  )

is equivalent to:

( transform-style: preserve-3d ) or (( -moz-transform-style: preserve-3d ) or 
(( -o-transform-style: preserve-3d ) or ( -webkit-transform-style: preserve-3d  )))

Note: when using both and and or operators, the parenthesis must be used in order to define the order in which they apply. If not, the condition is invalid leading to the whole at-rule to be ignored.

Examples

Testing for the support of a given CSS property

@supports (animation-name: test) {
    … /* specific CSS applied when animations are supported unprefixed */
    @keyframes { /* @supports being a CSS conditional group at-rule, it can includes other relevent at-rules */
      …
    }
}

Testing for the support of a given CSS property or a prefixed version

@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or
            (-ms-perspective: 10px) or (-o-perspective: 10px) ) {
    … /* specific CSS applied when 3D transforms, eventually prefixed, are supported */
}

Testing for the non-support of a specific CSS property

@supports ( not ((text-align-last:justify) or (-moz-text-align-last:justify) ){
    … /* specific CSS applied to simulate text-align-last:justify */
}

Specifications

Specification Status Comment
CSS Conditional Rules Module Level 3 Candidate Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 28.0 22 (22) [1] Not supported 12.1 Not supported
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported 22.0 (22) [1] Not supported 12.1 Not supported

[1] Gecko 17 to Gecko 21 supported this feature only if the user enables it by setting the config value layout.css.supports-rule.enabled to true.

See also

Document Tags and Contributors

最終更新者: Priyanka13,
サイドバーを隠す