I am using a fixed left .navbar
and I want to display the content of the .collapse
when my .navbar
is toggled (stacked to the left). I have successfully implemented this, but when I try to scroll the .navbar
while it is stacked, I have to set the .navbar
to overflow: auto
. However, if the overflow property is not set to visible when the .navbar
is toggled, the menu in the .collapse
is also not visible. How can I make the .navbar
scrollable and show the content of the .collapse
at the same time?
To better understand, refer to the picture below: https://i.sstatic.net/tptPt.png
CSS
.navbar {
background-color: #152e4d;
border-color: #12263f;
position: fixed;
overflow: auto;
padding: 16px;
min-height: 100vh;
top: 0;
left: 0;
right: 0;
z-index: 1030
}
.navbar.toggled {
width: 6.5rem !important;
padding: 0 !important;
}
.navbar.toggled .nav-item .collapse {
background-color: #152e4d;
border-radius: 5px;
border: 1px solid #102137;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
max-height: 22rem;
overflow-y: auto;
position: absolute;
left: calc(6.5rem + 1.5rem / 2);
z-index: 1;
top: 2px;
}
HTML
<nav id="mainNav" class="navbar navbar-expand-md navbar-dark nav-left">
<button class="navbar-toggler collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="">
<i class="bi bi-currency-bitcoin"></i>
<span>Brand</span>
</a>
<div class="navbar-collapse collapse" id="navbarsExampleDefault" style="">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="">
<i class="bi bi-graph-up"></i>
<span>Dashboard</span>
</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link" href="#collapse1" role="button" data-bs-toggle="collapse" aria-expanded="true" aria-controls="collapse1">
<i class="bi bi-box-seam"></i>
<span>Packages</span>
</a>
<div id="collapse1" class="collapse show" aria-labelledby="headingTwo" data-bs-parent="#navbarsExampleDefault">
<a class="dropdown-item">Action</a>
<a class="dropdown-item">Another action</a>
<a class="dropdown-item">Something else here</a>
</div>
</li>
</ul>
</div>
<div class="text-center d-none d-md-inline">
<button class="rounded-circle border-0" id="mininavToggle"></button>
</div>
</nav>