Tumgik
#personally im a mix of android and classic ^_^
troooob · 4 months
Text
(this can be for robotkin or ppl who just enjoy robots :3)
5K notes · View notes
suzanneshannon · 5 years
Text
How @supports Works
CSS has a neat feature that allows us to test if the browser supports a particular property or property:value combination before applying a block of styles — like how a @media query matches when, say, the width of the browser window is narrower than some specified size and then the CSS within it takes effect. In the same spirit, the CSS inside this feature will take effect when the property:value pair being tested is supported in the current browser. That feature is called @supports and it looks like this:
@supports (display: grid) { .main { display: grid; } }
Why? Well, that's a bit tricky. Personally, I find don't need it all that regularly. CSS has natural fallback mechanisms such that if the browser doesn't understand a property:value combination, then it will ignore it and use something declared before it if there is anything, thanks to the cascade. Sometimes that can be used to deal with fallbacks and the end result is a bit less verbose. I'm certainly not a it's-gotta-be-the-same-in-every-browser kinda guy, but I'm also not a write-elaborate-fallbacks-to-get-close kinda guy either. I generally prefer a situation where a natural failure of a property:value doesn't do anything drastic to destroy functionality.
That said, @supports certainly has use cases! And as I found out while putting this post together, plenty of people use it for plenty of interesting situations.
A classic use case
The example I used in the intro is a classic one that you'll see used in lots of writing about this topic. Here it is a bit more fleshed out:
/* We're gonna write a fallback up here in a minute */ @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; } }
Nice grid! Repeating and auto-filling columns is a sweet feature of CSS grid. But, of course, there are browsers that don't support grid, or don't support all the specific features of it that I'm using above there.
For example, iOS shipped support for CSS grid in version 10.2, but iOS has had flexbox support since version 7. That's a decent gap of people with older iOS devices that do support flexbox but not grid. I'm sure there are more example gaps like that, but you probably get the idea.
I was running on an older version of mobile safari and many many many many many sites were flat out broken that used grid
I’m waiting another year or so before messing about with it
— David Wells (@DavidWells) February 6, 2019
It may be acceptable to let the fallback for this be nothing, depending on the requirements. For example, vertically stacked block-level elements rather than a multi-column grid layout. That's often fine with me. But let's say it's not fine, like a photo gallery or something that absolutely needs to have some basic grid-like structure. In that case, starting with flexbox as the default and using @supports to apply grid features where they're supported may work better...
.photo-layout { display: flex; flex-wrap: wrap; > div { flex: 200px; margin: 1rem; } } @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; > div { margin: 0; } } }
The "fallback" is the code outside of the @supports block (the properties above the block in the example above), and the grid code is either inside or after. The @supports block doesn't change any specificity, so we need the source order to help make sure the overrides work.
Notice I had to reset the margin on the divs inside the @supports block. That's the kind of thing I find a bit annoying. There is just enough crossover between the two scenarios that it requires being super aware of how they impact each other.
Doesn't that make you wish it could be entirely logically separated...
There is "not" logic in @supports blocks, but that doesn't mean it should always be used
Jen Simmons put this example in an article called Using Feature Queries in CSS a few years ago:
/* Considered a BAD PRACTICE, at least if you're supporting IE 11 and iOS 8 and older */ @supports not (display: grid) { /* Isolated code for non-support of grid */ } @supports (display: grid) { /* Isolated code for support of grid */ }
Notice the not operator in the first block. That's checking for browsers that do not support grid in order to apply certain styles to those browsers. The reason this approach is considered bad practice is that the browser support for @supports itself has to be considered!. That's what makes this so dang tricky.
It's very appealing to write code in logically separated @supports blocks like that because then it's starting from scratch each time and doesn't need to be overriding previous values and dealing with those logical mind-benders. But let's go back to the same iOS situation we considered before... @supports shipped in iOS in version 9 (right between when flexbox shipped in iOS 7 and grid shipped in iOS 10.2). That means any flexbox fallback code in a @supports block using the not operator to check for (display: grid) {} support wouldn't work in either iOS 7 or 8, meaning the fallback now needs a fallback from working in browsers it otherwise would have. Phew!
The big reason to reach for @supports is to account for very different implementations of something depending on feature support where it becomes easier to reason and distinguish between those implementations if the blocks of code are separated.
We'll probably get to a point where we can use mutually-exclusive blocks like that without worry. Speaking of which...
@supports is likely to be more useful over time.
Once @supports is supported in all browsers you need to support, then it's good to start using it more aggressively and without having to factor in the complication of considering whether @supports itself is supported. Here's the support grid on that:
This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.
Desktop
ChromeOperaFirefoxIEEdgeSafari2812.122No129
Mobile / Tablet
iOS SafariOpera MobileOpera MiniAndroidAndroid ChromeAndroid Firefox9.0-9.246all4.47164
Basically, IE 11 and any iOS device stuck on iOS 8 are the pain points. If your requirements are already past those, then you're good to use @supports more freely.
The irony is that there hasn't been a ton of CSS features shipping that have big clear @supports use cases — but there are some! Apparently, it's possible to test new fancy stuff like Houdini:
Using it on my wedding website to check for Houdini support 🎩🐰
— Sam Richard (@Snugug) February 6, 2019
(I'm not sure entirely what you'd put in the @supports block to do that. Has anyone else done this?)
When @supports isn't doing anything useful
I've seen a good amount of @supports uses in the wild where the end result is exactly as it would be without using it. For example...
@supports (transform: rotate(5deg)) { .avatar { transform: rotate(5deg); } }
On some level, that makes perfect logical sense. If transforms are supported, use them. But it's unnecessary if nothing different is happening in a non-support scenario. In this case, the transform can fail without the @supports block and the result is the same.
Here's another example of that shaking out.
There are browser extensions for playing with @supports
There are two of them!
Feature Queries Manager by Ire Aderinokun
CSS Feature Toggle Extension by Keith Clark
They are both centered around the idea that we can write @supports blocks in CSS and then toggle them on and off as if we're looking at a rendering of the code in a browser that does or doesn't support that feature.
Here's a video of Keith's tool applied to the scenario using grid with a flexbox fallback:
This is fun to play with and is very neat tech. But in this exact scenario, if I was able to pull off the layout identically with flexbox, then I'd probably just do that and save that little bit of technical debt.
Ire's tool, which she wrote about in the article Creating The Feature Queries Manager DevTools Extension, has a slightly different approach in that it shows the feature queries that you actually wrote in your CSS and provides toggles to flip them on and off. I don't think it works through iframes though, so I popped open Debug Mode to use it on CodePen.
More real world use cases for @supports
Here's one from Erik Vorhes. He's styling some custom checkboxes and radio buttons here, but wraps all of it in a @supports block. None of the styling gets applied unless the block passes the support check.
@supports (transform: rotate(1turn)) and (opacity: 0) { /* all the styling for Erik's custom checkboxes and radio buttons */ }
Here are several more I've come across:
Joe Wright and Tiago Nunes mentioned using it for position: sticky;. I'd love to see a demo here! As in, where you go for position: sticky;, but then have to do something different besides let it fail for a non-supporting browser.
Keith Grant and Matthias Ott mention using it for object-fit: contain;. Matthias has a demo where positioning trickery is used to make an image sort of fill a container, which is then made easier and better through that property when it's available.
Ryan Filler mentions using it for mix-blend-mode. His example sets more opacity on an element, but if mix-blend-mode is supported, it uses a bit less and that property which can have the effect of seeing through an element on its own.
.thing { opacity: 0.5; } @supports (mix-blend-mode: multiply) { .thing { mix-blend-mode: multiply; opacity: 0.75; } }
Rik Schennink mentioned the backdrop-filter property. He says, "when it's supported the opacity of the background color often needs some fine tuning."
Nour Saud mentioned it can be used to detect Edge through a specific vendor-prefixed property: @supports (-ms-ime-align:auto) { }.
Amber Weinberg mentioned using it for clip-path because adjusting the sizing or padding of an element will accommodate when clipping is unavailable.
Ralph Holzmann mentioned using it to test for that "notch" stuff (environment variables).
Stacy Kvernmo mentioned using it for the variety of properties needed for drop capping characters. Jen Simmons mentions this use case in her article as well. There is an initial-letter CSS property that's pretty fantastic for drop caps, but is used in conjunction with other properties that you may not want to apply at all if initial-letter isn't supported (or if there's a totally different fallback scenario).
Here's a bonus one from Nick Colley that's not @supports, but @media instead! The spirit is the same. It can prevent that "stuck" hover state on touch devices like this:
@media (hover: hover) { a:hover { background: yellow; } }
Logic in @supports
Basic:
@supports (initial-letter: 4) { }
Not:
@supports not (initial-letter: 4) { }
And:
@supports (initial-letter: 4) and (transform: scale(2)) { }
Or:
@supports (initial-letter: 4) or (-webkit-initial-letter: 4) { }
Combos:
@supports ((display: -webkit-flex) or (display: -moz-flex) or (display: flex)) and (-webkit-appearance: caret) { }
JavaScript Variant
JavaScript has an API for this. To test if it exists...
if (window.CSS && window.CSS.supports) { // Apparently old Opera had a weird implementation, so you could also do: // !!((window.CSS && window.CSS.supports) || window.supportsCSS || false) }
To use it, either pass the property to it in one param and the value in another:
const supportsGrid = CSS.supports("display", "grid");
...or give it all in one string mirroring the CSS syntax:
const supportsGrid = CSS.supports("(display: grid)");
Selector testing
At the time of this writing, only Firefox supports this sort of testing (behind an experimental flag), but there is a way to test the support of selectors with @supports. MDN's demo:
@supports selector(A > B) { }
You?
Of course, we'd love to see Pens of @supports use cases in the comments. So share 'em!
The post How @supports Works appeared first on CSS-Tricks.
How @supports Works published first on https://deskbysnafu.tumblr.com/
0 notes
siliconwebx · 5 years
Text
How @supports Works
CSS has a neat feature that allows us to test if the browser supports a particular property or property:value combination before applying a block of styles — like how a @media query matches when, say, the width of the browser window is narrower than some specified size and then the CSS within it takes effect. In the same spirit, the CSS inside this feature will take effect when the property:value pair being tested is supported in the current browser. That feature is called @supports and it looks like this:
@supports (display: grid) { .main { display: grid; } }
Why? Well, that's a bit tricky. Personally, I find don't need it all that regularly. CSS has natural fallback mechanisms such that if the browser doesn't understand a property:value combination, then it will ignore it and use something declared before it if there is anything, thanks to the cascade. Sometimes that can be used to deal with fallbacks and the end result is a bit less verbose. I'm certainly not a it's-gotta-be-the-same-in-every-browser kinda guy, but I'm also not a write-elaborate-fallbacks-to-get-close kinda guy either. I generally prefer a situation where a natural failure of a property:value doesn't do anything drastic to destroy functionality.
That said, @supports certainly has use cases! And as I found out while putting this post together, plenty of people use it for plenty of interesting situations.
A classic use case
The example I used in the intro is a classic one that you'll see used in lots of writing about this topic. Here it is a bit more fleshed out:
/* We're gonna write a fallback up here in a minute */ @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; } }
Nice grid! Repeating and auto-filling columns is a sweet feature of CSS grid. But, of course, there are browsers that don't support grid, or don't support all the specific features of it that I'm using above there.
For example, iOS shipped support for CSS grid in version 10.2, but iOS has had flexbox support since version 7. That's a decent gap of people with older iOS devices that do support flexbox but not grid. I'm sure there are more example gaps like that, but you probably get the idea.
I was running on an older version of mobile safari and many many many many many sites were flat out broken that used grid
I’m waiting another year or so before messing about with it
— David Wells (@DavidWells) February 6, 2019
It may be acceptable to let the fallback for this be nothing, depending on the requirements. For example, vertically stacked block-level elements rather than a multi-column grid layout. That's often fine with me. But let's say it's not fine, like a photo gallery or something that absolutely needs to have some basic grid-like structure. In that case, starting with flexbox as the default and using @supports to apply grid features where they're supported may work better...
.photo-layout { display: flex; flex-wrap: wrap; > div { flex: 200px; margin: 1rem; } } @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; > div { margin: 0; } } }
The "fallback" is the code outside of the @supports block (the properties above the block in the example above), and the grid code is either inside or after. The @supports block doesn't change any specificity, so we need the source order to help make sure the overrides work.
Notice I had to reset the margin on the divs inside the @supports block. That's the kind of thing I find a bit annoying. There is just enough crossover between the two scenarios that it requires being super aware of how they impact each other.
Doesn't that make you wish it could be entirely logically separated...
There is "not" logic in @supports blocks, but that doesn't mean it should always be used
Jen Simmons put this example in an article called Using Feature Queries in CSS a few years ago:
/* Considered a BAD PRACTICE, at least if you're supporting IE 11 and iOS 8 and older */ @supports not (display: grid) { /* Isolated code for non-support of grid */ } @supports (display: grid) { /* Isolated code for support of grid */ }
Notice the not operator in the first block. That's checking for browsers that do not support grid in order to apply certain styles to those browsers. The reason this approach is considered bad practice is that the browser support for @supports itself has to be considered!. That's what makes this so dang tricky.
It's very appealing to write code in logically separated @supports blocks like that because then it's starting from scratch each time and doesn't need to be overriding previous values and dealing with those logical mind-benders. But let's go back to the same iOS situation we considered before... @supports shipped in iOS in version 9 (right between when flexbox shipped in iOS 7 and grid shipped in iOS 10.2). That means any flexbox fallback code in a @supports block using the not operator to check for (display: grid) {} support wouldn't work in either iOS 7 or 8, meaning the fallback now needs a fallback from working in browsers it otherwise would have. Phew!
The big reason to reach for @supports is to account for very different implementations of something depending on feature support where it becomes easier to reason and distinguish between those implementations if the blocks of code are separated.
We'll probably get to a point where we can use mutually-exclusive blocks like that without worry. Speaking of which...
@supports is likely to be more useful over time.
Once @supports is supported in all browsers you need to support, then it's good to start using it more aggressively and without having to factor in the complication of considering whether @supports itself is supported. Here's the support grid on that:
This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.
Desktop
ChromeOperaFirefoxIEEdgeSafari2812.122No129
Mobile / Tablet
iOS SafariOpera MobileOpera MiniAndroidAndroid ChromeAndroid Firefox9.0-9.246all4.47164
Basically, IE 11 and any iOS device stuck on iOS 8 are the pain points. If your requirements are already past those, then you're good to use @supports more freely.
The irony is that there hasn't been a ton of CSS features shipping that have big clear @supports use cases — but there are some! Apparently, it's possible to test new fancy stuff like Houdini:
Using it on my wedding website to check for Houdini support 🎩🐰
— Sam Richard (@Snugug) February 6, 2019
(I'm not sure entirely what you'd put in the @supports block to do that. Has anyone else done this?)
When @supports isn't doing anything useful
I've seen a good amount of @supports uses in the wild where the end result is exactly as it would be without using it. For example...
@supports (transform: rotate(5deg)) { .avatar { transform: rotate(5deg); } }
On some level, that makes perfect logical sense. If transforms are supported, use them. But it's unnecessary if nothing different is happening in a non-support scenario. In this case, the transform can fail without the @supports block and the result is the same.
Here's another example of that shaking out.
There are browser extensions for playing with @supports
There are two of them!
Feature Queries Manager by Ire Aderinokun
CSS Feature Toggle Extension by Keith Clark
They are both centered around the idea that we can write @supports blocks in CSS and then toggle them on and off as if we're looking at a rendering of the code in a browser that does or doesn't support that feature.
Here's a video of Keith's tool applied to the scenario using grid with a flexbox fallback:
This is fun to play with and is very neat tech. But in this exact scenario, if I was able to pull off the layout identically with flexbox, then I'd probably just do that and save that little bit of technical debt.
Ire's tool, which she wrote about in the article Creating The Feature Queries Manager DevTools Extension, has a slightly different approach in that it shows the feature queries that you actually wrote in your CSS and provides toggles to flip them on and off. I don't think it works through iframes though, so I popped open Debug Mode to use it on CodePen.
More real world use cases for @supports
Here's one from Erik Vorhes. He's styling some custom checkboxes and radio buttons here, but wraps all of it in a @supports block. None of the styling gets applied unless the block passes the support check.
@supports (transform: rotate(1turn)) and (opacity: 0) { /* all the styling for Erik's custom checkboxes and radio buttons */ }
Here are several more I've come across:
Joe Wright and Tiago Nunes mentioned using it for position: sticky;. I'd love to see a demo here! As in, where you go for position: sticky;, but then have to do something different besides let it fail for a non-supporting browser.
Keith Grant and Matthias Ott mention using it for object-fit: contain;. Matthias has a demo where positioning trickery is used to make an image sort of fill a container, which is then made easier and better through that property when it's available.
Ryan Filler mentions using it for mix-blend-mode. His example sets more opacity on an element, but if mix-blend-mode is supported, it uses a bit less and that property which can have the effect of seeing through an element on its own.
.thing { opacity: 0.5; } @supports (mix-blend-mode: multiply) { .thing { mix-blend-mode: multiply; opacity: 0.75; } }
Rik Schennink mentioned the backdrop-filter property. He says, "when it's supported the opacity of the background color often needs some fine tuning."
Nour Saud mentioned it can be used to detect Edge through a specific vendor-prefixed property: @supports (-ms-ime-align:auto) { }.
Amber Weinberg mentioned using it for clip-path because adjusting the sizing or padding of an element will accommodate when clipping is unavailable.
Ralph Holzmann mentioned using it to test for that "notch" stuff (environment variables).
Stacy Kvernmo mentioned using it for the variety of properties needed for drop capping characters. Jen Simmons mentions this use case in her article as well. There is an initial-letter CSS property that's pretty fantastic for drop caps, but is used in conjunction with other properties that you may not want to apply at all if initial-letter isn't supported (or if there's a totally different fallback scenario).
Here's a bonus one from Nick Colley that's not @supports, but @media instead! The spirit is the same. It can prevent that "stuck" hover state on touch devices like this:
@media (hover: hover) { a:hover { background: yellow; } }
Logic in @supports
Basic:
@supports (initial-letter: 4) { }
Not:
@supports not (initial-letter: 4) { }
And:
@supports (initial-letter: 4) and (transform: scale(2)) { }
Or:
@supports (initial-letter: 4) or (-webkit-initial-letter: 4) { }
Combos:
@supports ((display: -webkit-flex) or (display: -moz-flex) or (display: flex)) and (-webkit-appearance: caret) { }
JavaScript Variant
JavaScript has an API for this. To test if it exists...
if (window.CSS && window.CSS.supports) { // Apparently old Opera had a weird implementation, so you could also do: // !!((window.CSS && window.CSS.supports) || window.supportsCSS || false) }
To use it, either pass the property to it in one param and the value in another:
const supportsGrid = CSS.supports("display", "grid");
...or give it all in one string mirroring the CSS syntax:
const supportsGrid = CSS.supports("(display: grid)");
Selector testing
At the time of this writing, only Firefox supports this sort of testing (behind an experimental flag), but there is a way to test the support of selectors with @supports. MDN's demo:
@supports selector(A > B) { }
You?
Of course, we'd love to see Pens of @supports use cases in the comments. So share 'em!
The post How @supports Works appeared first on CSS-Tricks.
😉SiliconWebX | 🌐CSS-Tricks
0 notes
kalajustice07-blog · 7 years
Text
Quick 'N Simple Paleo Mixed greens.
Along with a little group, participants possess the possibility to get to understand one another well, without obtaining extremely uninterested or even eating a lot of opportunity. Powerful PS4 line-up no question, but, FF7 is actually only console launching" there, and also Shenmue is dated for 2017; We believe our aim at from 2017 holiday is actually accessible". This video game blends every thing you adored about the last Lego Harry Potter activity and improves that with the contests from the latter one-half from the Harry Potter franchise business. I really would like to do this ... but I will definitely must continuously check in with your blog post to tell me !! I inspect your blog site every now and then, yet I should begin examining it more often! Im just waiting for video games to be developed exclusively to benefit from the hardware in the appropriate technique, i suggest im in no hurry currently considering exactly how my ps4 pro is still misbehaving, yet im sure the issues will certainly be actually ironed out prior to anything valuable launches. I desire you ALL OF to enjoy this reviewed the method I have therefore I'm visiting leave this there certainly, feel in one's bones this manual is wonderful, exciting, deep. The PS4 is basically silent, also when playing some high-ranking games for extended periods of time. There is some disagreement that such an activity will definitely eat your opportunity enough that due to the opportunity you are done, there will be actually a lot more out there for Switch all set to play. Every year gamers as well as organisers break their backs to put on grassroots events, as well as along with events such as the E-League and Red Upward Kumite coming to the fore, there is actually currently a very clear pathway for combating games to have towards big-budget esports. That is such an excellent suggestion to possess a different blog rather than handling a thousand emails. And, increasingly, you'll merely obtain the total video game features on new-gen systems. The authentic Myst's 'slide show' design of action has been actually improved right into a free-roaming adventure, updating a game that's still a classic, along with sensibly durable touchscreen navigation. While our team've referred to the future video game as Red Dead Atonement 2, the label is currently unidentified - therefore begin your estimates. And also appeal, releasing re-mastered activities on a brand new device works on Sony and also Microsoft's equipments as a result of the sheer number of titles released on either console. An arithmetic board game supplies a wonderful means to integrate mathematics, board style as well as video game policies. This seems too simplistic to point out folks do not possess as much money as they utilized to. (Blame Brexit!) What I assume is actually taking place is people do not have the money to justify handing over ₤ 45 on an all new activity they might take or even leave any longer - certainly not when they understand this'll be more affordable in a handful of weeks. That additionally doesn't resemble the firm is actually visiting create it feasible to incorporate more video games as there's been actually no idea of on the internet connectivity for future downloads. For more info on click through the next web page review the web page. Gamings permit trainees to learn at their very own speed without consistent adult oversight. Be sure to take a look at our best PS4 activities round-up, or head to our listing from the top upcoming PS4 games for 2016 to obtain a consider the future of PS4 gaming. Next time you see Game from Thrones, take a more detailed examine some of the costumes, generated through seamstress Michele Carragher and professional Michele Clapton. Minecraft's increasing results is actually unusual, to ensure, yet this's an enthusiastic sign that the best recipe from game auto mechanics, accessibility, and neighborhood participation could create private jobs monetarily practical online. Lake Myvatn, near the city of Akureyri, is actually where Mance Rayder's wildling soldiers creates camping ground in period 3, while the neighboring cavern of Grjotagja is actually where Jon Snowfall and also Ygritte make love. That's a difficult publication to summarize, however essentially 2 historical magicians prepare their pair of best students against one another in a wonderful competition. The greatest which is that Chrome does not assist Oneness, a 3D activity engine that works with Firefox, Opera and Trip. The impacts from nurturing, caring dads on their little girls' lives can be gauged in females from all ages. Our company attempt to keep this list as new as achievable, so if your beloved falls off the chart at that point it's not a negative video game ... there is actually merely much more available to make an effort. Within this manual, the activity continued in their very own way yet I had good enough of that. There was actually a lot refer to that without it being actually considerable - at the very least not to me because they completely shed my focus each time activity talk arised. Yet this's in simple fact an Android treasure - a remarkably creative activity that tampers time traveling ... as well as your head. It tries therefore hard though, in spite of everything I merely stated, and also duplicates a WHOLE LOT from the unique Far Cry set from games. Our experts've acquired a lot from well-liked indie activities at reduced costs this week together with a few that are actually a little more mainstream. Lego Wonder's Avengers is actually measured PEGI 7 in Europe & ESRB E10+ in The U.S.A. for everybody 7 to 10 years or older. There are couple of video games as close to their resource product as The Hitchhiker's Overview of the Universe. Sony revealed Eliminate Stress at its PlayStation Experience event in Sin city last year, a free-to-play, swift as well as habit forming" top-down multiplayer activity activity from its San Diego center. But disappointingly for the modding neighborhood, Rockstar chose to introduce the PlayStation 2 model from the activity ahead of the Personal Computer model. We are said to at the starting that The Warm Shot and The Game Plan participated in out at the same time. THIS BOOK WAS EVERY THING THAT JUST Is Actually A COMBO FROM DESIRE, soccer as well as affection INNUENDOS COMPLETELY! In other words, then, a degree of dream role-playing wrapped around a entertaining and approachable card game. That is actually experienced that in addition to some outstanding instances from students showing remarkable ability as well as skill in particular games, or even pupils that are actually expected to become high up on the merit checklist in college assessments, very most other students need to participate in one game or even various other, not always for obtaining accolades, but also for the benefit of sporting activity.
0 notes
suzanneshannon · 5 years
Text
How @supports Works
CSS has a neat feature that allows us to test if the browser supports a particular property or property:value combination before applying a block of styles — like how a @media query matches when, say, the width of the browser window is narrower than some specified size and then the CSS within it takes effect. In the same spirit, the CSS inside this feature will take effect when the property:value pair being tested is supported in the current browser. That feature is called @supports and it looks like this:
@supports (display: grid) { .main { display: grid; } }
Why? Well, that's a bit tricky. Personally, I find don't need it all that regularly. CSS has natural fallback mechanisms such that if the browser doesn't understand a property:value combination, then it will ignore it and use something declared before it if there is anything, thanks to the cascade. Sometimes that can be used to deal with fallbacks and the end result is a bit less verbose. I'm certainly not a it's-gotta-be-the-same-in-every-browser kinda guy, but I'm also not a write-elaborate-fallbacks-to-get-close kinda guy either. I generally prefer a situation where a natural failure of a property:value doesn't do anything drastic to destroy functionality.
That said, @supports certainly has use cases! And as I found out while putting this post together, plenty of people use it for plenty of interesting situations.
A classic use case
The example I used in the intro is a classic one that you'll see used in lots of writing about this topic. Here it is a bit more fleshed out:
/* We're gonna write a fallback up here in a minute */ @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; } }
Nice grid! Repeating and auto-filling columns is a sweet feature of CSS grid. But, of course, there are browsers that don't support grid, or don't support all the specific features of it that I'm using above there.
For example, iOS shipped support for CSS grid in version 10.2, but iOS has had flexbox support since version 7. That's a decent gap of people with older iOS devices that do support flexbox but not grid. I'm sure there are more example gaps like that, but you probably get the idea.
I was running on an older version of mobile safari and many many many many many sites were flat out broken that used grid
I’m waiting another year or so before messing about with it
— David Wells (@DavidWells) February 6, 2019
It may be acceptable to let the fallback for this be nothing, depending on the requirements. For example, vertically stacked block-level elements rather than a multi-column grid layout. That's often fine with me. But let's say it's not fine, like a photo gallery or something that absolutely needs to have some basic grid-like structure. In that case, starting with flexbox as the default and using @supports to apply grid features where they're supported may work better...
.photo-layout { display: flex; flex-wrap: wrap; > div { flex: 200px; margin: 1rem; } } @supports (display: grid) { .photo-layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; > div { margin: 0; } } }
The "fallback" is the code outside of the @supports block (the properties above the block in the example above), and the grid code is either inside or after. The @supports block doesn't change any specificity, so we need the source order to help make sure the overrides work.
Notice I had to reset the margin on the divs inside the @supports block. That's the kind of thing I find a bit annoying. There is just enough crossover between the two scenarios that it requires being super aware of how they impact each other.
Doesn't that make you wish it could be entirely logically separated...
There is "not" logic in @supports blocks, but that doesn't mean it should always be used
Jen Simmons put this example in an article called Using Feature Queries in CSS a few years ago:
/* Considered a BAD PRACTICE, at least if you're supporting IE 11 and iOS 8 and older */ @supports not (display: grid) { /* Isolated code for non-support of grid */ } @supports (display: grid) { /* Isolated code for support of grid */ }
Notice the not operator in the first block. That's checking for browsers that do not support grid in order to apply certain styles to those browsers. The reason this approach is considered bad practice is that the browser support for @supports itself has to be considered!. That's what makes this so dang tricky.
It's very appealing to write code in logically separated @supports blocks like that because then it's starting from scratch each time and doesn't need to be overriding previous values and dealing with those logical mind-benders. But let's go back to the same iOS situation we considered before... @supports shipped in iOS in version 9 (right between when flexbox shipped in iOS 7 and grid shipped in iOS 10.2). That means any flexbox fallback code in a @supports block using the not operator to check for (display: grid) {} support wouldn't work in either iOS 7 or 8, meaning the fallback now needs a fallback from working in browsers it otherwise would have. Phew!
The big reason to reach for @supports is to account for very different implementations of something depending on feature support where it becomes easier to reason and distinguish between those implementations if the blocks of code are separated.
We'll probably get to a point where we can use mutually-exclusive blocks like that without worry. Speaking of which...
@supports is likely to be more useful over time.
Once @supports is supported in all browsers you need to support, then it's good to start using it more aggressively and without having to factor in the complication of considering whether @supports itself is supported. Here's the support grid on that:
This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.
Desktop
ChromeOperaFirefoxIEEdgeSafari2812.122No129
Mobile / Tablet
iOS SafariOpera MobileOpera MiniAndroidAndroid ChromeAndroid Firefox9.0-9.246all4.47164
Basically, IE 11 and any iOS device stuck on iOS 8 are the pain points. If your requirements are already past those, then you're good to use @supports more freely.
The irony is that there hasn't been a ton of CSS features shipping that have big clear @supports use cases — but there are some! Apparently, it's possible to test new fancy stuff like Houdini:
Using it on my wedding website to check for Houdini support 🎩🐰
— Sam Richard (@Snugug) February 6, 2019
(I'm not sure entirely what you'd put in the @supports block to do that. Has anyone else done this?)
When @supports isn't doing anything useful
I've seen a good amount of @supports uses in the wild where the end result is exactly as it would be without using it. For example...
@supports (transform: rotate(5deg)) { .avatar { transform: rotate(5deg); } }
On some level, that makes perfect logical sense. If transforms are supported, use them. But it's unnecessary if nothing different is happening in a non-support scenario. In this case, the transform can fail without the @supports block and the result is the same.
Here's another example of that shaking out.
There are browser extensions for playing with @supports
There are two of them!
Feature Queries Manager by Ire Aderinokun
CSS Feature Toggle Extension by Keith Clark
They are both centered around the idea that we can write @supports blocks in CSS and then toggle them on and off as if we're looking at a rendering of the code in a browser that does or doesn't support that feature.
Here's a video of Keith's tool applied to the scenario using grid with a flexbox fallback:
This is fun to play with and is very neat tech. But in this exact scenario, if I was able to pull off the layout identically with flexbox, then I'd probably just do that and save that little bit of technical debt.
Ire's tool, which she wrote about in the article Creating The Feature Queries Manager DevTools Extension, has a slightly different approach in that it shows the feature queries that you actually wrote in your CSS and provides toggles to flip them on and off. I don't think it works through iframes though, so I popped open Debug Mode to use it on CodePen.
More real world use cases for @supports
Here's one from Erik Vorhes. He's styling some custom checkboxes and radio buttons here, but wraps all of it in a @supports block. None of the styling gets applied unless the block passes the support check.
@supports (transform: rotate(1turn)) and (opacity: 0) { /* all the styling for Erik's custom checkboxes and radio buttons */ }
Here are several more I've come across:
Joe Wright and Tiago Nunes mentioned using it for position: sticky;. I'd love to see a demo here! As in, where you go for position: sticky;, but then have to do something different besides let it fail for a non-supporting browser.
Keith Grant and Matthias Ott mention using it for object-fit: contain;. Matthias has a demo where positioning trickery is used to make an image sort of fill a container, which is then made easier and better through that property when it's available.
Ryan Filler mentions using it for mix-blend-mode. His example sets more opacity on an element, but if mix-blend-mode is supported, it uses a bit less and that property which can have the effect of seeing through an element on its own.
.thing { opacity: 0.5; } @supports (mix-blend-mode: multiply) { .thing { mix-blend-mode: multiply; opacity: 0.75; } }
Rik Schennink mentioned the backdrop-filter property. He says, "when it's supported the opacity of the background color often needs some fine tuning."
Nour Saud mentioned it can be used to detect Edge through a specific vendor-prefixed property: @supports (-ms-ime-align:auto) { }.
Amber Weinberg mentioned using it for clip-path because adjusting the sizing or padding of an element will accommodate when clipping is unavailable.
Ralph Holzmann mentioned using it to test for that "notch" stuff (environment variables).
Stacy Kvernmo mentioned using it for the variety of properties needed for drop capping characters. Jen Simmons mentions this use case in her article as well. There is an initial-letter CSS property that's pretty fantastic for drop caps, but is used in conjunction with other properties that you may not want to apply at all if initial-letter isn't supported (or if there's a totally different fallback scenario).
Here's a bonus one from Nick Colley that's not @supports, but @media instead! The spirit is the same. It can prevent that "stuck" hover state on touch devices like this:
@media (hover: hover) { a:hover { background: yellow; } }
Logic in @supports
Basic:
@supports (initial-letter: 4) { }
Not:
@supports not (initial-letter: 4) { }
And:
@supports (initial-letter: 4) and (transform: scale(2)) { }
Or:
@supports (initial-letter: 4) or (-webkit-initial-letter: 4) { }
Combos:
@supports ((display: -webkit-flex) or (display: -moz-flex) or (display: flex)) and (-webkit-appearance: caret) { }
JavaScript Variant
JavaScript has an API for this. To test if it exists...
if (window.CSS && window.CSS.supports) { // Apparently old Opera had a weird implementation, so you could also do: // !!((window.CSS && window.CSS.supports) || window.supportsCSS || false) }
To use it, either pass the property to it in one param and the value in another:
const supportsGrid = CSS.supports("display", "grid");
...or give it all in one string mirroring the CSS syntax:
const supportsGrid = CSS.supports("(display: grid)");
Selector testing
At the time of this writing, only Firefox supports this sort of testing (behind an experimental flag), but there is a way to test the support of selectors with @supports. MDN's demo:
@supports selector(A > B) { }
You?
Of course, we'd love to see Pens of @supports use cases in the comments. So share 'em!
The post How @supports Works appeared first on CSS-Tricks.
How @supports Works published first on https://deskbysnafu.tumblr.com/
0 notes