TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The @supports CSS rule

124 pointsby callumlockeover 8 years ago

10 comments

geostyxover 8 years ago
Site down, cached version: <a href="http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:http:&#x2F;&#x2F;www.lottejackson.com&#x2F;learning&#x2F;supports-will-change-your-life" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:http:&#x2F;&#x2F;...</a>
评论 #12878069 未加载
JD557over 8 years ago
I like the fact that this exists, but it seems like the kind of hacks that go against the philosophy of progressive enhancement.<p>The thing that I like about progressive enhancement is that it &quot;forces&quot; the HTML documents actually represent the content. I should be able to render any site (excluding web-apps, I guess) with CSS and Javascript disabled, preferably with semantic HTML. This makes that site not only accessible to humans, but machines as well.<p>I see a bunch of websites that have 2 versions of certain elements (for example, navigation menus) in the HTML that are hidden with @media rules to make the site &quot;responsive&quot;. I&#x27;m scared that this @supports rule will be used in the same way.<p>Disclaimer: I am not a frontend web developer, so my understanding of progressive enhancement might be wrong.
achairapartover 8 years ago
Not mentioned, there is also a CSS.supports() method available in JS:<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;CSS&#x2F;supports" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;CSS&#x2F;support...</a>
评论 #12874607 未加载
sapeienover 8 years ago
According to MDN, `@supports` is part of the CSS3 spec, defined in 2012. In 2016, it&#x27;s time to start using it. Web development in a nutshell.
评论 #12873535 未加载
评论 #12876311 未加载
评论 #12878809 未加载
wandaover 8 years ago
While it&#x27;s nice to not need Modernizr, or JavaScript at all, it&#x27;s generally only useful for features added <i>after</i> the @supports support landed. As others have mentioned, there&#x27;s also the problem of false positives, and you could end up with a lorra lorra @supports statements if you include vendor prefixing as well — not a problem JavaScript has to put up with, because you can just define a prefixing function and save many lines of code.<p>Here&#x27;s the problem vis-á-vis compatibility. CSS Animations are supported back to Safari 4; @supports landed in Safari 9.<p>For instance:<p><pre><code> @supports (-webkit-animation-name: blink){ .cursor { -webkit-animation-name: onoff; -webkit-animation-duration: .9s; -webkit-animation-timing-function: cubic-bezier(.4,0,.2,1); -webkit-animation-iteration-count: infinite; } } </code></pre> That&#x27;s actually damaging, because there won&#x27;t be a browser that supports @supports <i>and doesn&#x27;t</i> support CSS animation. This statement will activate the animation only in Safari 9+, despite the feature enjoying support beforehand. By conditioning the animation on support for <i>animation-name</i>, we&#x27;re actually preventing the feature from showing up where it ought to.<p>Of course, @supports is very useful for bleeding edge stuff like animation-play-state, which just landed in Chrome (and I dare say Firefox) as a byproduct of the Web Animations API.<p><i>animation-play-state</i> let&#x27;s us control whether an animation (let&#x27;s say an infinite one) is paused or playing. So, if you imagine a scrolling marquee (for the sake of irony), for instance, you could conditionally pause the marquee on hover by setting:<p><pre><code> @supports (animation-play-state: paused){ .marquee:hover { animation-play-state: paused } } </code></pre> You may be thinking &quot;that&#x27;s effing ridiculous, I could just add that CSS property anyway and if it&#x27;s not supported it won&#x27;t work, simple&quot; — and you&#x27;d be right to say so.<p>It would be equally pointless to write this:<p><pre><code> @supports (will-change: transform){ .element { will-change: transform; } } </code></pre> because if the property is not supported, it simply won&#x27;t do anything, and it will not affect anything else or prevent CSS parsing. @supports is pointless as a mere wrapper because there&#x27;s no need for containment.<p>However, @supports is not for applying potentially unsupported properties only; it&#x27;s for conditionally activating&#x2F;altering entire aspects of your website based on there being support for a <i>crucial</i> feature.<p>More useful code might look like this example:<p><pre><code> @supports (animation-play-state: paused){ .marquee { white-space: nowrap; animation-name: marquee; animation-duration: 20s; animation-timing-function: linear; animation-delay: 1s; animation-fill-mode: forwards; will-change: transform; } .marquee:hover { animation-play-state: paused; } } </code></pre> This would be useful if, for instance, it would harm usability to have an unstoppable marquee of images&#x2F;products, so with this sort of code you could have that marquee display as something more mundane, like a grid of items, and if the ability to pause the animation is supported, then convert it into a scrolling marquee gallery of items.<p>It&#x27;s also potentially useful for things like <i>mix-blend-mode</i>, if you want to apply some kind of fancy effects with a fallback to a simple, one colour overlay:<p><pre><code> .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(rgba(31,10,25,.2), rgba(3,81,176,.6)); } @supports (mix-blend-mode: difference){ .overlay { mix-blend-mode: difference; background: radial-gradient(rgba(31,10,25,.2), rgba(176, 109, 3, 0.6)); } } </code></pre> See, if you wanted to apply the difference blending mode but have a similar colour theme, the background of the overlay would need to be basically the opposite, so you can use a @supports block to conditionally change the colour to suit whatever the blending-mode requires.
评论 #12880455 未加载
mapleoinover 8 years ago
<a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20161010115605&#x2F;http:&#x2F;&#x2F;www.lottejackson.com&#x2F;learning&#x2F;supports-will-change-your-life" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20161010115605&#x2F;http:&#x2F;&#x2F;www.lottej...</a>
jessedhillonover 8 years ago
This seems like a reduction in readability from either declaring properties in an order such that browsers which don&#x27;t support the syntax will still have a fallback declaration:<p><pre><code> .foobar { background: red; &#x2F;* fallback declaration *&#x2F; background: poorly-supported; &#x2F;* preferred declaration *&#x2F; } </code></pre> or using platform-specific property prefixes.<p>Personally, I&#x27;d rather see the entire definition block for a selector in one place than have to consult multiple conditional declarations.
评论 #12879204 未加载
ErrantXover 8 years ago
Key question; are there a subset of these nextgen(?) css features supported in browsers that don&#x27;t support @supports?
评论 #12879131 未加载
tedmistonover 8 years ago
Tl;dr - We can use @supports instead of Modernizr to check whether a browser supports a particular CSS property. Though @supports itself is only supported by 77% of browsers, in unsupported browsers, the @supports blocks are ignored making them effectively supported everywhere. We can use this in production today.
评论 #12873308 未加载
评论 #12873255 未加载
评论 #12873633 未加载
pitajover 8 years ago
This looks cool. But does anyone else think that the circular text wrapping around the example image is super ugly? It makes it much less readable for me.