Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.
Описание
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.
@supports
gives CSS the ability 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
.
Синтаксис
A supports condition consists of one or several declarations combined by different logical operators. Precedence of operators can be overruled by using parentheses.
Синтаксис объявления
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.
Оператор not
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) )
Предупреждение: there is no need to enclose the not
operator between two parentheses when at the top level. To combine it with other operators, like and
and or
, the parentheses are required.
Оператор and
From two expressions, the and
operator creates a new expression consisting in the conjunction of the two original ones; 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 parentheses:
(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))
Оператор or
From two expressions, the or
operator creates a new expression consisting in the disjunction of the two original ones; 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 parentheses:
( 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 )))
Предупреждение: when using both and
and or
operators, the parentheses 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.
Формальный синтаксис
@supports <supports-condition> { <group-rule-body> }
Примеры
Тестирование заданного свойства
@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 relevant at-rules */ … } }
Тестирование заданного свойства или его версии с префиксом
@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 */ }
Тестирование неподдерживаемого или специфического свойства
@supports not ((text-align-last:justify) or (-moz-text-align-last:justify) ){ … /* specific CSS applied to simulate text-align-last:justify */ }
Спецификации
Спецификация | Статус | Комментарий |
---|---|---|
CSS Conditional Rules Module Level 3 Определение '@supports' в этой спецификации. |
Кандидат в рекомендации | Первоначальное определение. |
Совместимость с браузерами
Особенность | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Базовая поддержка | 28.0 | (Да) | 22 (22) [1] | Нет | 12.1 | 9 |
Особенность | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Базовая поддержка | Нет | ? | 22.0 (22) [1] | Нет | 12.1 | 9 | 28.0 |
[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
.
Смотрите также
- The CSSOM class
CSSSupportsRule
, and theCSS.supports
method that allows to perform the same check via JavaScript.