Css: Workaround to backdrop-filter?
To replicate the effect of backdrop-filter: blur()
, layer a blur()
filtered ::before
pseudo-element, absolutely positioned behind your target. Don't forget the target element's background needs to be transparent for the blur effect to come through.
This technique gives a similar visual vibe to a backdrop filter, blurring the content under the .effect-behind
element. By adjusting blur(10px)
, you can control just how much you blur your vision, i.e., the blur intensity.
Navigating browser differences
The fast answer solves your problem, but what about different browsers? Here's how you can accommodate these variations and future-proof your masterpiece.
Working with @supports
Use @supports
to write a more adaptive CSS code. This feature checks whether a browser can handle a particular property or value pair, allowing you to apply styles accordingly.
On turning feature flags on
As of now, some browsers, specifically Chrome and Safari, would need flags or prefixes enabled to be able to use this feature:
- Safari:
-webkit-backdrop-filter
- Chrome: Just enable the 'Experimental Web Platform features' flag (
chrome://flags/#enable-experimental-web-platform-features
).
Translucent backgrounds: subtle but effective
For those poor souls (I mean, browsers) that can't support backdrop-filter
, a translucent background color will do. It won't blur the beneath content, but it sure will soften things up a bit!
Venturing with SVG filters
SVG
filters can serve as a strong alternative with its ability to create complex visual effects. Just remember, with great power comes great performance hits & limitations especially for dynamic content.
Pseudo-elements to the rescue
Bring pseudo-elements into the picture to mimic the backdrop blur effect. But remember, z-index ain't just for stacking pizzas:
Delivering that 'frosted window' look
Cool as a cucumber, eh? Let's understand this in a more visual way.
Tada! You've got your own frost-like effect without having to rely on backdrop-filter
.
Strategies for pushing the envelope
How about we sprinkle some extra seasoning? Let's learn more about progressive enhancement.
Checking browser support dynamically
With JavaScript, you can check the browser support for backdrop-filter on the fly and apply an alternative blurring effect.
Preparing for the future
Regularly tune into developer doc updates and browser release notes. For instance, Chrome v76 included support for backdrop-filter
as default.
Learning from practical examples
Platforms like CodePen or JSFiddle have a bunch of examples you can learn from and get your feet wet before you dive into the big leagues.
Was this article helpful?