Backdrop-filter: blur(20px); doesnt work ;(
I have a dropdown menu that when pressed the button menu changes from display none to display block and I want to make #account-info-main background would have backdrop-filter: blur(20px); but for me it doesn`t appear. https://ibb.co/FnNWYMB
HTML:
<div class="account">
<button class="profile-dropdown" id="profilie-dropdown-id" onclick="show_list_profile()">
<i class="fas fa-user-circle"></i>
</button>
<div id="account-info-main">
<div class="account-info">
Other code
</div>
</div>
</div>
CSS:
.account {
align-items: center;
text-align: center;
}
.profile-dropdown:hover {
transition: 0.5s;
background-color: rgb(0, 0, 0);
}
.profile-dropdown {
color: rgb(233, 233, 233);
font-size: 20px;
border-radius: 100%;
width: 50px;
height: 50px;
border: 3px solid #ff8906;
background-color: #0000007c;
cursor: pointer;
}
.account-info {
color: rgb(0, 0, 0);
width: 100%;
height: 100%;
}
#account-info-main {
position: absolute;
transform: translateX(-70%);
margin-top: 1%;
border-radius: 10px;
height: 350px;
width: 400px;
display: none;
border: 3px solid rgb(190, 190, 190);
background-color: rgba(212, 212, 212, 0.507);
backdrop-filter: blur(20px);
}
JS:
function show_list_profile() {
var dropdown = document.getElementById("account-info-main");
if (dropdown.style.display == "block") {
dropdown.style.display = "none";
} else {
dropdown.style.display = "block";
}
}
2
Answers
Problem was of nested other elements who had backdrop-filter: blur, solution found in backdrop-filter not working for nested elements in Chrome
You have to place the
backdrop-filter: blur(20px)
on some background element, between your content and your dropdown menu. Example:Breakdown:
#parent
div to allow the background to spread the whole page. This is not strictly necessary, you may want to remove it so the backdrop cover the whole page OR only this parent div, depending on your needs.#background
div hidden by default, which create the backdrop effect behind the dropdown. It has a the backdrop CSS, and alsopointer-events: none;
to allow clicks to pass through it. Its visibility gets toggled the same way as the dropdown is. It has az-index: 1;
.z-index: 2;
to the dropdown (#account-info-main
) to allow it to be above the background and the blur effect.