Using @supports to fork CSS
When you’re building out a responsive web design, attempting to provide a single design that works everywhere, on every device, it’s a simple fact that you’ll frequently encounter situations when features or techniques are not supported on certain devices. It might be that you want to do something with a newer selector, such as :has()
, which we looked at earlier in the chapter. In such an instance, you may want to create a fork in your CSS. If the browser supports a feature, provide one set of rules; if it doesn’t, provide different rules.
This is the kind of situation that gets handled by if
/else
or switch
statements in JavaScript. In CSS, we use the @supports
at-rule.
Now, before we dig into feature queries, it is worth pointing out a straightforward way of providing fallbacks for older browsers. Suppose we want to use some of our new viewport-related length units but ensure we have some kind of fallback for older browsers...