I have an div element that is transparent but blurs everything behind it, through a combination of backdrop-filter: blur() and rgba(255, 255, 255, 0). You can see an example in this JSFiddle, the code of which is replicated below. Most of this code is from the MDN Docs page for backdrop-filter, with small modifications by myself.
Iād like to make it so that the blurring effect, instead of ending sharply at the border lines of the div, fades out in a gradient (kind of like using a box-shadow with a blur property, but the shadow is invisible and the blur affects whateverās behind it instead).
How can I achieve this effect?
Iāve looked around for a solution, but I havenāt been able to find anyone asking the same question or a way to apply a backdrop-filter directly to a shadow. The only workaround I can think of is creating several transparent divs around the main one, with incrementally increasing sizes and decreasing backdrop-filter: blur() values, to create the illusion of a blur gradient, but that seems quite āhackyā and Iād like to avoid it if there is at all a ācleanerā method.
It is, yeah. Any idea how I can fix the issue on my end? This is all for a website, so I would need it to work on most/all popular browsers.
filter and backdrop-filter are both fully compatible with both Chrome and Safari (at least on PNGs, as opposed to SVGs), so I donāt see where the issue is coming from. Hereās the compatibility data from MDN:
I just checked the Pen, and this keeps getting weirder. It looks different, but not in the way it appeared in your screenshot (which is the way I want it to look). Hereās some screenshots:
The CodePen version seems less blurred, but the border is just as sharp.
@hbar1st@lasjorg Sorry to ping you, but youāve both been very helpful in the past. Do you have any idea why this is all happening? (Long story short: @nickrgās solution seems to work on their end but not mine, and also looks different when I view it on JSFiddle vs. CodePen.)
Hey, Iām back. Iāve gone through your code and fixed a few things. You donāt really have any errors, just some double selectors and so on. Iāve redone the page as properly as I know how. Let me know if it works for you now:
One thing I also noticed was you forgot the āaā on the rgba color declaration. Maybe this was causing the issue. It seems like it might - thatās what determines the transparency of the div and is exactly what the backdrop filter affects. Itās corrected now. Please let me know if it works for you.
By the way, I think those two screenshots you last shared with me, with the strange blur difference, is actually no difference at all. I think it just seems so because the background is a lot larger on the CodePen version.
Thanks. I copied most of it from the MDN documentation page as a quick example, so I didnāt put much effort into it.
I normally use rgba() the way you did, like rgba(255,255,255,0) but in the code I copied from MDN, they made it rgb(255 255 255 / 30%), which seemed to work, so I didnāt bother to change it (except by changing 30% to 0%.)
Unfortunately, the change you made doesnāt seem to have changed anything on my end. I checked the new CodePen, and the border still looks sharp on my end.
That might be the reason behind the difference, but Iām honestly not sure.
I appreciate your help my man, but donāt dedicate too much time to this if youāre busy. Iāll either cheese it through several divs or just not implement it, I guess.
Alright, I see. No, itās fine, I like solving problems like this. What Iām going to do is try to find another way to achieve the same effect and see if it works on your browser. Just one question: does your blurry div have to be transparent, or are you planning on making it a certain color?
Got it. Working on it. I might not be able to come up with something, but Iāll try. As you say, thereās always a dirty solution if nothing else works.