I am trying to show and hide a navbar based on whether a variable is set to true or false. I am able to get the Navbar to show/hide however, my problem happens when I try to set the Navbar to always show at the large breakpoint.
In other words, I want the navbar to be constantly showing at the large breakpoint and above even if the variable controlling the navbar is set to false. However, this does not happen. I can’t figure out what is wrong with my code. Can someone please help me?
My code is here:
<div className={`lg:!relative z-50 ${showNavBar ? "absolute" : "hidden"} `}>
<Navbar showNavBar={showNavBar} handleNavBar={handleNavBar} />
</div>
2
Answers
You need to override the
display: none
applied byhidden
whenshowNavBar
is falsy by using adisplay
utility, likeblock
fordisplay: block
:You can prefix the variables inside the brackets with "max-lg" so they only apply below the large breakpoint: