I am attempting to create a Bootstrap 5.2 Mega Menu with a full page-wide background, but I am encountering some challenges.
Here is my basic navigation setup:
<nav class="navbar navbar-expand">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Item 1</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="megaMenuDropdown" style="background-color: blue;">
<div class="container" style="background-color: red;">
<div class="row">
<div class="col-12">
COL 12 WITH INSIDE CONTAINER
</div>
</div>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item 3</a>
</li>
</ul>
</div>
</div>
</nav>
This produces the following layout: https://i.sstatic.net/c43cLygY.png
When I add position: static !important
, as suggested in several older posts, I get the following result:
https://i.sstatic.net/gYweEu2I.png
While this is close, I need the horizontal background to extend beyond the container and cover the entire page (illustrated in blue in my example).
To achieve a full-page width, I added width: 100vw;
to the .dropdown-menu
item, but it resulted in the following layout:
https://i.sstatic.net/kZh7zp5b.png
The menu is now 100% width starting from the trigger nav
element, extending beyond the viewport. I am struggling to find a solution that positions it at the start of the page or centers it nicely to cover the entire page.
I have come across similar examples online, such as this one, where the issue persists: https://i.sstatic.net/pb0eUkfg.png These menus also start from the element and extend outside the window.
Can anyone provide a solution to make the menu extend full page starting from the left side of the page?
I am wondering if there have been any recent changes causing this behavior, as I have not encountered similar issues before?
The project relies on Bootstrap, and I would prefer not to resort to creating a custom navigation menu.
Thank you.