When I hover over an item in the navbar, a horizontal dropdown menu currently opens as shown below (note the width of the dropdown menu): https://i.sstatic.net/824OVkWT.png
What am I aiming for?
I want to expand the horizontal dropdown menu like in the image below, but only on desktop version. I want the dropdown menu to be as wide as the container (the one Bootstrap already uses with the container class) that is used in my navbar and will also be used throughout the site body.
In the image (montage/collage), I'm inspecting the navbar with Chrome to highlight the navbar container and show you how wide I'd like the dropdown menu to be. https://i.sstatic.net/ANCfM18J.png
Can anyone assist me in achieving this? I've made several attempts, all unsuccessful.
document.addEventListener("DOMContentLoaded", function() {
const dropdowns = document.querySelectorAll(".nav-item.dropdown");
dropdowns.forEach(dropdown => {
dropdown.addEventListener("mouseenter", function() {
const menu = this.querySelector(".dropdown-menu-horizontal");
if (menu) menu.style.display = "flex";
});
dropdown.addEventListener("mouseleave", function() {
const menu = this.querySelector(".dropdown-menu-horizontal");
if (menu) menu.style.display = "none";
});
});
});
* {
box-sizing: border-box;
}
/* Navbar styles */
.navbar {
background-color: #000033;
padding: 0 !important;
display: flex;
align-items: center;
position: relative;
z-index: 1000;
box-sizing: border-box;
}
/* Brand logo and text styles */
.logo {
height: 80px;
margin-right: 10px;
}
.brand-text {
color: #ffffff;
display: flex;
flex-direction: column;
justify-content: center;
text-align: left;
line-height: 1;
}
.fondazione {
font-size: 0.80em;
font-weight: normal;
letter-spacing: 0.28em;
}
.surname {
font-size: 2.4rem;
font-weight: bold;
letter-spacing: 0.05em;
}
/* Colored rectangle under navbar links */
.navbar-nav .nav-link {
color: #ffffff;
margin-right: 10px;
padding: 0 10px;
line-height: normal;
position: relative;
height: 100%;
display: flex;
align-items: center;
}
.navbar-nav .nav-link:hover::after {
content: '';
display: block;
width: 100%;
height: 3px;
background-color: #459439;
position: absolute;
bottom: 0;
left: 0;
z-index: 1000;
}
/* Remove dropdown arrow */
.nav-link.dropdown-toggle::after {
display: none;
}
/* Horizontal dropdown menu styling */
.dropdown-menu-horizontal {
display: none;
background-color: #000033 !important;
padding: 20px !important;
min-width: 100%;
border-radius: 0;
position: absolute;
left: 0;
top: 97% !important;
z-index: 9999;
}
.dropdown-item-horizontal {
color: #ffffff;
display: inline-flex;
align-items: center;
padding: 10px 20px;
margin-right: 30px;
white-space: nowrap;
}
.dropdown-item-horizontal img {
width: 50px;
height: 50px;
margin-right: 15px;
}
.dropdown-item-horizontal:hover {
color: #d4d4ff;
text-decoration: none;
}
.nav-item:hover .dropdown-menu-horizontal {
display: flex;
justify-content: space-around;
}
@media (max-width: 768px) {
.navbar-expand-md .navbar-nav .nav-link {
padding-top: 20px;
padding-bottom: 20px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<nav class="navbar navbar-expand-md navbar-dark mb-0">
<div class="container align-items-stretch">
<a class="navbar-brand d-flex align-items-center" href="#">
<img src="img/..." alt="Logo" class="logo">
<div class="brand-text">
<span class="fondazione">AAAAAAA</span>
<span class="surname">XXXX</span>
</div>
</a>
<button class="navbar-toggler align-self-center" 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 ml-auto h-100">
<li class="nav-item dropdown">
...
<li class="nav-item"><a class="nav-link" href="#">Item 8</a></li>
</ul>
</div>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22414d504762100c31b05180907">[email protected]</a>/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>