This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Support for a CSS property isn’t the only thing you can check with @supports()
, you can also check support for a selector.
I knew you can check whether a property is supported by the current browser and apply styles accordingly.
<div hidden class="grid">
Your browser supports <code>display: grid</code> 🎉
</div>
@supports (display: grid) {
.grid {
display: block
}
}
display: grid
🎉
What I didn’t know is that you can do the same, but for a selector using the selector()
function.
<div hidden class="has">
Your browser supports <code>:has()</code> 🎉
</div>
@supports selector(:has(a)) {
.has {
display: block
}
}
:has()
🎉
You can also reverse the query.
@supports not selector(:has(a)) {
/* You're Firefox, Opera Mini, etc. fallback */
}
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2022-12-07T09:38:54+00:00) Day 54: testing for the support of a selector. Retrieved from https://www.scien.cx/2022/12/07/day-54-testing-for-the-support-of-a-selector/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.