I am currently facing two issues with my sidebar.
- The top part gets cut off on mobile devices.
- The sidebar is expanded by default on mobile devices, which is not the desired behavior. Also, when it is collapsed, the content of the page does not shift to the left as it should.
I am using Bootstrap 5.
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
padding: 45px 0 0;
box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%), 0 2px 10px 0 rgb(0 0 0 / 5%);
width: 220px;
}
.sidebar .active {
border-radius: 5px;
box-shadow: 0 2px 5px 0 rgb(0 0 0 / 16%), 0 2px 10px 0 rgb(0 0 0 / 12%);
}
@media (max-width: 767px) {
.main {
padding-right: 40px;
padding-left: 220px;
/* 180 + 40 */
}
}
<link href="https://cdn.jsdelivr.net/npm/example/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/example/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<div class="container-fluid">
<div class="col-md-12 col-sm-12">
<div class="row">
<div class="col-md-4 col-sm-4">
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ path('app_dashboard') }}">
<span data-feather="home"></span> Test
</a>
<a class="nav-link" aria-current="page" href="{{ path('app_dashboard') }}">
<span data-feather="home"></span> Test
</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">
<span data-feather="file"></span> Test
</a>
<a class="nav-link" aria-current="page" href="#">
<span data-feather="file"></span> Test
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file-plus"></span> Test
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="users"></span> Test
</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="col-md-8 col-sm-8">
{% block body %}{% endblock %}
</div>
</div>
</div>
</div>