Design comparison
Solution retrospective
Hello Frontend Mentor community,
Does anyone know why my menu (in the Mobile View) does not display when the toggleButton has been clicked? How can I fix it?
Your help is much appreciated!
Community feedback
- @9CB5Posted over 1 year ago
The
display: none
in.menuList
takes precedence over the.displayMenu
class that you toggle when you click the button. So the menu will never show. There are two ways you can solve this:1.) Hacky but quicker way. Add an
!important
keyword todisplay: block
inside the.displayMenu
class. But bear in mind this is bad practice as you're bypassing the natural order of precedence of your CSS.2.) Modify the
display: none
in.menuList
using JS with something likemenu.style.display = "block"
when the hamburger is clicked.Marked as helpful0@kxnzxPosted over 1 year ago@9CB5 Hello Chris, thank you for your clear explanation. I choose to solve it with your second solution, it works now! Much appreciated! :)
At the time I finished the CSS I realized that it was unnecessary for me to wrap the <ul class="menuListItems"> inside the <div class="menuList">. I didn't want to correct it, because it would mess up the whole layout. Is this where it went wrong with the precedence? In other words if I did not have the <div class="menuList"> wrapped around <ul class="menuListItems"> would this prevented me from having this issue?
1@9CB5Posted over 1 year ago@kxnzx No, because the issue lies in
<div class="menuList">
which is the parent element.When the hamburger button is clicked, the statement above becomes
<div class="menuList displayMenu">
So now, you have two competing classes in your menu, and whichever class that is declared last in your css file takes precedence.
In your css file,
.displayMenu
and.menuList
is declared at line 102 and 105 respectively. So.menuList
takes precedence.Marked as helpful0@kxnzxPosted over 1 year ago@9CB5 I replaced the .displayMenu below .menuList so that .displayMenu takes precedence, this however also did not work.
1@9CB5Posted over 1 year ago@kxnzx You have modified your SASS file but forgot to compile it to CSS. It should work once you've done this :)
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord