104 lines
2.8 KiB
HTML
104 lines
2.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Collapsible Sidebar (Icons Visible)</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
overflow-x: hidden;
|
|
}
|
|
#sidebar {
|
|
width: 250px;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
height: 100vh;
|
|
background: #343a40;
|
|
color: #fff;
|
|
transition: all 0.3s;
|
|
overflow: hidden;
|
|
}
|
|
#sidebar.collapsed {
|
|
width: 70px;
|
|
}
|
|
#sidebar .nav-link {
|
|
color: #adb5bd;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
transition: all 0.3s;
|
|
}
|
|
#sidebar.collapsed .nav-link span {
|
|
opacity: 0;
|
|
visibility: hidden;
|
|
width: 0;
|
|
}
|
|
#sidebar .nav-link.active {
|
|
background: #495057;
|
|
color: #fff;
|
|
}
|
|
#content {
|
|
margin-left: 250px;
|
|
transition: all 0.3s;
|
|
padding: 20px;
|
|
}
|
|
#content.fullwidth {
|
|
margin-left: 70px;
|
|
}
|
|
.toggle-btn {
|
|
position: fixed;
|
|
top: 15px;
|
|
left: 15px;
|
|
z-index: 999;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Toggle Button -->
|
|
<button class="btn btn-secondary toggle-btn" id="toggleSidebar">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<!-- Sidebar -->
|
|
<div id="sidebar">
|
|
<h5 class="p-3 border-bottom text-center text-truncate">
|
|
<span class="sidebar-title">My App</span>
|
|
</h5>
|
|
<nav class="nav flex-column px-2">
|
|
<a class="nav-link active" href="#"><i class="bi bi-house-door"></i> <span>Dashboard</span></a>
|
|
<a class="nav-link" href="#"><i class="bi bi-people"></i> <span>Users</span></a>
|
|
<a class="nav-link" href="#"><i class="bi bi-graph-up"></i> <span>Reports</span></a>
|
|
<a class="nav-link" href="#"><i class="bi bi-gear"></i> <span>Settings</span></a>
|
|
</nav>
|
|
</div>
|
|
|
|
<!-- Main Content -->
|
|
<div id="content">
|
|
<h2>Dashboard</h2>
|
|
<p>This is your main content area. Click the button to collapse or expand the sidebar. Icons stay visible when collapsed.</p>
|
|
</div>
|
|
|
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
$(function () {
|
|
$('#toggleSidebar').on('click', function () {
|
|
$('#sidebar').toggleClass('collapsed');
|
|
$('#content').toggleClass('fullwidth');
|
|
});
|
|
|
|
$('#sidebar .nav-link').on('click', function () {
|
|
$('#sidebar .nav-link').removeClass('active');
|
|
$(this).addClass('active');
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|