I have the following code to apply a blur backdrop-filter
on a background image:
<div className="container">
<div className="blur" />
<div className="box">
<h2>Start editing to see some magic happen!</h2>
</div>
</div>
CSS:
.container {
height: 100vh;
width: 100vw;
}
.blur {
position: absolute;
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
background-image: url("https://upload.wikimedia.org/wikipedia/en/6/62/Kermit_the_Frog.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.blur::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
backdrop-filter: blur(60px);
-webkit-backdrop-filter: blur(60px);
}
It seems to work well until a resize the window, the filter will not resize like the background-image. I tried changing the parent div
to position: relative
but it didn’t work either
6
Answers
I resorted to using the following code for now in case anybody is wondering
::before
is not a good option for this. You’re better off applyingfilter:blur
to the image itself.It seems to be a WebKit issue, as it does work fine for me in Firefox. I kinda solved it by making the blurred div a really big size so it always covers the entire screen. This does however seem to cause some small artifacts like flickering in Firefox.
This will apparently be fixed in Chrome 112 (
currently betanow stable).I could reproduce the problem in Chrome 110 and 111, but not in 112, nor 113. Tested under MacOS.
The release date of Chrome 112 was March 29, 2023. See https://chromestatus.com/roadmap
So I guess, for some developers the correct answer is "just wait".
The fix for now, is to just add this extra style to the same class/ID that the backdrop-filter is on.
Works perfectly for me.
Example:
adding another filter with a size of 0 will fix this issue