<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bootstrap 5 Side Bar Navigation</title>
<!-- bootstrap 5 css -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous" />
<!-- BOX ICONS CSS-->
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.5/css/boxicons.min.css" rel="stylesheet" />
<!-- custom css -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Side-Nav -->
<div class="side-navbar active-nav d-flex justify-content-between flex-wrap flex-column" id="sidebar">
<ul class="nav flex-column text-white w-100">
<a href="#" class="nav-link h3 text-white my-2">
Responsive </br>SideBar Nav
</a>
<li href="#" class="nav-link">
<i class="bx bxs-dashboard"></i>
<span class="mx-2">Home</span>
</li>
<li href="#" class="nav-link">
<i class="bx bx-user-check"></i>
<span class="mx-2">Profile</span>
</li>
<li href="#" class="nav-link">
<i class="bx bx-conversation"></i>
<span class="mx-2">Contact</span>
</li>
</ul>
<span href="#" class="nav-link h4 w-100 mb-5">
<a href=""><i class="bx bxl-instagram-alt text-white"></i></a>
<a href=""><i class="bx bxl-twitter px-2 text-white"></i></a>
<a href=""><i class="bx bxl-facebook text-white"></i></a>
</span>
</div>
<!-- Main Wrapper -->
<div class="p-1 my-container active-cont">
<!-- Top Nav -->
<nav class="navbar top-navbar navbar-light bg-light px-5">
<a class="btn border-0" id="menu-btn"><i class="bx bx-menu"></i></a>
</nav>
<!--End Top Nav -->
<h3 class="text-dark p-3">RESPONSIVE SIDEBAR NAV 💻 📱
</h3>
<p class="px-3">Responsive navigation sidebar built using <a class="text-dark" href="https://getbootstrap.com/">Bootstrap 5</a>.</p>
<p class="px-3"><a href="https://github.com/harshitjain-hj" class="text-dark">Checkout my Github</a></p>
</div>
<!-- bootstrap js -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
min-height: 100vh;
background-color: #fff;
}
.side-navbar {
width: 250px;
height: 100%;
position: fixed;
margin-left: -300px;
background-color: #100901;
transition: 0.5s;
}
.nav-link:active,
.nav-link:focus,
.nav-link:hover {
background-color: #ffffff26;
}
.my-container {
transition: 0.4s;
}
.active-nav {
margin-left: 0;
}
/* for main section */
.active-cont {
margin-left: 250px;
}
#menu-btn {
background-color: #100901;
color: #fff;
margin-left: -62px;
}
.my-container input {
border-radius: 2rem;
padding: 2px 20px;
}
var menu_btn = document.querySelector("#menu-btn");
var sidebar = document.querySelector("#sidebar");
var container = document.querySelector(".my-container");
menu_btn.addEventListener("click", () => {
sidebar.classList.toggle("active-nav");
container.classList.toggle("active-cont");
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.