@supports and CSS.supports (JavaScript) directives to help developers determine if a user's browser can cope with a CSS property or not. Let's look at them in action!@supports , if it is red, then no. You can also look at the message in the browser console.)@supports directive is the same as for @media requests: @supports(prop:value) { /* */ } @supports directive provides developers with various uses. @supports (display: flex) { div { display: flex; } } @supports paired with the word not checks for the lack of support for any property: @supports not (display: flex) { div { float: left; } /* */ } or and and string of words: /* or */ @supports (display: -webkit-flex) or (display: -moz-flex) or (display: flex) { /* */ } /* and */ @supports (display: flex) and (-webkit-appearance: caret) { /* */ } /* and and or */ @supports ((display: -webkit-flex) or (display: -moz-flex) or (display: flex)) and (-webkit-appearance: caret) { /* */ } @supports same as for @media requests.@supports is the window.CSS.supports method. There are two options for using it. The first involves passing two arguments — the property and its value: var supportsFlex = CSS.supports("display", "flex"); var supportsFlexAndAppearance = CSS.supports("(display: flex) and (-webkit-appearance: caret)"); var supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false); @supports is to install a specific backup set of styles and then replace them with others, in case the desired property is supported. A great reason to use @supports is the description of the location of the elements. Some newer browsers support flexbox , while others lag behind. In this case, you can write the following code: section { float: left; } @supports (display: -webkit-flex) or (display: -moz-flex) or (display: flex) { section { display: -webkit-flex; display: -moz-flex; display: flex; float: none; } } @supports will appear after developers spend more time experimenting with this new technology.@supports , you should spend some time installing the latest edge version of Canary, Firefox Nightly, or Opera Next. Opera 12.1, WebKit Nightly and Firefox Nightly all support @supports . Older versions of Firefox provide appropriate support after enabling the [layout.CSS.supports-rule.enabled] .@supports is a welcome addition to the CSS and JavaScript specifications. Determining browser-specific technology support is best practice, and @supports is a more convenient and appropriate way to do this than various hacks. I suspect that in the next couple of years we will see a surge in the use of the @supports directive, simultaneously with the increasing popularity and convenience of flexbox.Source: https://habr.com/ru/post/178021/
All Articles