Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Bootstrap Layout with Collapsible Sidebar</title>
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
- <style>
- #sidebar {
- min-width: 250px;
- max-width: 250px;
- height: calc(100vh - 56px);
- position: fixed;
- top: 56px;
- left: -250px;
- background-color: #f8f9fa;
- transition: all 0.3s;
- z-index: 1000;
- }
- #sidebar.active {
- left: 0;
- }
- #content {
- width: 100%;
- padding: 20px;
- min-height: 100vh;
- transition: all 0.3s;
- margin-top: 56px;
- }
- .overlay {
- display: none;
- position: fixed;
- width: 100vw;
- height: 100vh;
- background: rgba(0, 0, 0, 0.5);
- z-index: 998;
- opacity: 0;
- transition: all 0.5s ease-in-out;
- }
- .overlay.active {
- display: block;
- opacity: 1;
- }
- @media (max-width: 768px) {
- #sidebar {
- margin-left: -250px;
- }
- #sidebar.active {
- margin-left: 0;
- }
- }
- </style>
- </head>
- <body>
- <!-- Top bar with logo, hamburger, and logout -->
- <div class="bg-light px-3 py-2 d-flex justify-content-between align-items-center fixed-top">
- <div class="d-flex align-items-center">
- <button type="button" id="sidebarCollapse" class="btn btn-light me-2">
- <i class="fas fa-bars"></i>
- </button>
- <div class="logo">
- <img src="https://placehold.co/150x50" alt="Logo" class="img-fluid">
- </div>
- </div>
- <button class="btn btn-outline-danger">Logout</button>
- </div>
- <!-- Sidebar -->
- <nav id="sidebar">
- <div class="position-sticky">
- <ul class="nav flex-column">
- <li class="nav-item">
- <a class="nav-link active" href="#">
- <i class="fas fa-home me-2"></i>Dashboard
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">
- <i class="fas fa-user me-2"></i>Profile
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">
- <i class="fas fa-cog me-2"></i>Settings
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">
- <i class="fas fa-envelope me-2"></i>Messages
- </a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">
- <i class="fas fa-question-circle me-2"></i>Help
- </a>
- </li>
- </ul>
- </div>
- </nav>
- <!-- Overlay -->
- <div class="overlay"></div>
- <!-- Main content -->
- <div id="content">
- <h1>Welcome to the Dashboard</h1>
- <p>Click the hamburger menu to toggle the sidebar.</p>
- <p>This is your main content area. You can add any content here.</p>
- </div>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- const sidebar = document.getElementById('sidebar');
- const sidebarCollapse = document.getElementById('sidebarCollapse');
- const overlay = document.querySelector('.overlay');
- sidebarCollapse.addEventListener('click', function() {
- sidebar.classList.toggle('active');
- overlay.classList.toggle('active');
- });
- overlay.addEventListener('click', function() {
- sidebar.classList.remove('active');
- overlay.classList.remove('active');
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement