Bootstrap 5 Sidebar
Bootstrap 5 Sidebar
Bootstrap 5 Sidebar
League
HTML
<div class="main-container d-flex">
<div class="sidebar" id="side_nav">
<div class="header-box px-2 pt-3 pb-4 d-flex justify-content-between">
<h1 class="fs-4"><span class="bg-white text-dark rounded shadow px-2 me-2">CL</span>
<span
class="text-white">Coding League</span></h1>
<button class="btn d-md-none d-block close-btn px-1 py-0 text-white"><i
class="fal fa-stream"></i></button>
</div>
</ul>
</div>
<div class="content">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container-fluid">
<div class="d-flex justify-content-between d-md-none d-block">
<button class="btn px-1 py-0 open-btn me-2"><i class="fal fa-stream"></i></button>
<a class="navbar-brand fs-4" href="#"><span class="bg-dark rounded px-2 py-0 text-
white">CL</span></a>
</div>
<button class="navbar-toggler p-0 border-0" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<i class="fal fa-bars"></i>
</button>
<div class="collapse navbar-collapse justify-content-end"
id="navbarSupportedContent">
<ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Profile</a>
</li>
</ul>
</div>
</div>
</nav>
#side_nav{
background: #000;
min-width: 250px;
max-width: 250px;
transition: all 0.3s;
}
.content{
min-height: 100vh;
width: 100%;
}
hr.h-color{
background: #eee;
}
.sidebar li.active{
background: #eee;
border-radius: 8px;
}
@media(max-width: 767px){
#side_nav{
margin-left: -250px;
position: absolute;
min-height: 100vh;
z-index: 1;
}
#side_nav.active{
margin-left: 0;
}
}
JS
$(".sidebar ul li").on('click', function () {
$(".sidebar ul li.active").removeClass('active');
$(this).addClass('active');
});
$('.open-btn').on('click', function () {
$('.sidebar').addClass('active');
});
$('.close-btn').on('click', function () {
$('.sidebar').removeClass('active');
})