This will probably won't work, you cannot check whether @supports
is supported or not by CSS only, your example is completely fine here, but there's no option for a straight approach here, for example you are using this :
@supports (@supports) {
/* Styles */
}
Now that won't actually work, may be for Chrome Canary, this is fine @supports
but when it goes ahead to check between parenthesis, it fails, why? It expects a CSS property: value
pair inside the parenthesis and not any @
rule, it actually checks whether any property is valid or not, even if you replace that with @supports (@font-face)
won't work, further down, I'll explain you with a demo
When you use @supports
, it comes with a keyword called not
to check whether a specific style is supported by the browser or not, if yes, than apply, else apply other...
Example
@supports (-webkit-border-radius: 6px) {
div:nth-of-type(1) {
color: red;
}
}
@supports not (-moz-border-radius: 6px) {
div:nth-of-type(2) {
color: blue;
}
}
Demo (Note : This works only on chrome canary as of now)
Explanation :
@supports (-webkit-border-radius: 6px)
will check in Chrome Canary that whether a property called -webkit-border-radius
is supported, if yes than go ahead, change the color of first div
to red
and it does, cuz Chrome Canary does support -webkit
properties while the second will fail as Chrome doesn't support -moz
prefixed properties, it will paint blue because I am using not
here
@supports not (-moz-border-radius: 6px)
---^---
Hopefully FAQ
1) Why none of the styles are applied in browser?
That's because your browser doesn't support @supports
yet and hence none will apply as browser will just ignore @supports
rules
From the W3C
The ‘@supports’ rule is a conditional group rule whose condition tests
whether the user agent supports CSS property:value pairs