I am having trouble with a navbar when it’s on tablet and mobile size. When I click on the dropdown button I need it to take up the whole page. Basically it has to take up the whole height when I click on the dropdown button for mobile or tablet. I think I need to use JavaScript for it but I don’t know how exactly.
This is my navbar. I’m using Bootstrap 4 and also some CSS to edit it but I just need to somehow make it for tablet and mobile like I explained above.
<nav class="navbar navbar-expand-lg navbar-light bg-yellow px-5 py-3 font-weight-bold" id="navbar">
<div class="logo d-flex flex-column">
<a href="index.html" class="mx-auto"><img src="./Design/Logo.png" width="40" height="40" class="logo-img"></a>
<a class="navbar-brand mx-auto font-weight-bold" href="#">Logo</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav w-90 justify-content-around ml-lg-auto">
<li class="nav-item">
<a class="nav-link" href="#">Academy</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Academy</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Academy</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Academy</a>
</li>
<li class="nav-item justify-self-end">
<a href="./contact.html" class="btn btn-danger">Button</a>
</li>
</ul>
</div>
</nav>
This is how its supposed to look like when clicked on the dropdown button when on tablet or mobile—basically it has to take up the whole space.
2
Answers
I’m guessing that you want the navbar to be full-height when the button is clicked. For that you’ll need a javascript function:
This script tag will be placed at bottom of the body tag. And what it basically does is giving
height: 100%;
to the#navbar
when called.Now we need to call the function when the button is clicked. So, we’ll add
onclick="toggleNav();"
to the button. Like this:If you check your webpage now, you’ll see that the
#navbar
DOES get theheight: 100%;
when the button is triggered. But you won’t see anything happen, that is because our html tag’s height is limited. So, lets fix that by adding these css codes:Let me know if this is what you wanted.
From what I am able to understand you want the navbar to cover the entire screen by hiding the content.
In bootstrap 5 there is offcanvas component for this functionality.
To implement similar functionality in bootstrap 4 you would need to use jQuery.
Here is an to use off-canvas functionality in bootstrap 4.
Hope this helps.