- This topic has 15 replies, 3 voices, and was last updated 2 years ago by
Ying.
-
AuthorPosts
-
May 23, 2021 at 12:21 pm #1795187
Victor
Hi,
I am trying to make my sub-menu items look the same as my navigation bar. Main navigation is here. This CSS works well:
.main-navigation {backdrop-filter: blur(5px);}
But sub-menus are still not blurred. When I try
.main-navigation *
, it works, but because of the opacity, the result is wrong. Also when applying the rule to the entire<ul>
sub-menu, nothing happens. It only works when styling the<li>
elements, but still, result is wrong because of background opacity applied to the entire ul.Thank you.
May 23, 2021 at 6:00 pm #1795337Elvin
StaffCustomer SupportHi Victor,
..but still, result is wrong because of background opacity applied to the entire ul.
Can you share any mockup image of your expected results?
Note: The support for this CSS property is limited. While that can work on Chrome, I believe that won’t run well on Firefox.
May 24, 2021 at 5:12 am #1795834Victor
Hi,
Here is how it looks now:
I want both the main navigation and the sub-menu to look the same. Currently, the sub-menu is not blurred.If I blur the sub-menu, it changes the color altogether:
So, my expected result is: submenu background to look exactly like the main menu background.
May 24, 2021 at 5:27 pm #1796663Elvin
StaffCustomer SupportAh I see.
You’re aiming for something like this: https://share.getcloudapp.com/jkuPdWpq (I’ve removed the BG color, for now)
In that case, you need a bit of CSS workaround. By default, the backdrop-filter doesn’t work on an element if its ancestor element has one.
That said, we can use pseudo-element to apply things.
Remove how you’ve been applying the effect and try this CSS instead:
.main-navigation:before,
.main-navigation ul.sub-menu:before {
backdrop-filter: blur(5px);
content: “”;
display: block;
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
}.main-navigation{
position: relative;
}May 25, 2021 at 12:56 am #1796924Victor
Hi, yes, you are right about the result I want to achieve. Thank you for this code, but it doesn’t work. The blur is not present at all, I don’t know why. I tried to put
!important
, but still nothing happens.May 25, 2021 at 1:03 am #1796935Elvin
StaffCustomer SupportYou must remove the previous CSS you’ve added first.
You have to remove this:
.main-navigation { backdrop-filter: blur(5px); }
May 25, 2021 at 1:06 am #1796941Victor
It’s removed, you can check on the live site now.
May 25, 2021 at 1:18 am #1796952Elvin
StaffCustomer SupportYou then add this:
.main-navigation:before, .main-navigation ul.sub-menu:before { backdrop-filter: blur(5px); content: ""; display: block; height: 100%; width: 100%; position: absolute; left: 0; top: 0; } .main-navigation{ position: relative; }
Make sure it’s
content: "";
notcontent: โโ;
curly apostrophe won’t work.See it in action here – https://share.getcloudapp.com/yAur7e5R
May 25, 2021 at 1:19 am #1796955Victor
Now it works! Great advice. Thank you.
May 25, 2021 at 1:46 am #1796983Elvin
StaffCustomer SupportHere’s the key issue incase that happens again when you try to apply it on other parts.
“In that case, you need a bit of CSS workaround. By default, the backdrop-filter doesnโt work on an element if its ancestor element has one.”
We used
:before
pseudo element because CSS pseudo elements are not read as ancestor elements. That way, it works. ๐No problem. Glad you got it to finally work. ๐
May 25, 2021 at 1:49 am #1796990Victor
Thanks for this explanation.
May 25, 2021 at 1:50 am #1796993Elvin
StaffCustomer SupportNo problem. ๐
May 27, 2021 at 10:04 am #1800583Victor
Hi, I am checking on mobile and seems blur doesn’t work. On desktop is ok.
May 27, 2021 at 10:59 am #1800638Ying
StaffCustomer SupportHi Victor,
You can try to add this CSS for mobile:
@media (max-width: 768px) { #menu-primary-menu:before { backdrop-filter: blur(5px); content: ""; display: block; height: 100%; width: 100%; position: absolute; left: 0; top: 0; } }
May 27, 2021 at 11:09 pm #1801010Victor
now it works, Thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.