[BootStrap 4] : Cacher "sidebar" par défaut
Bonjour, j'ai créé cette sidebar (collapsible), mais elle s'affiche par défaut, cependant, j'aimerais la cacher par défaut.
Voici le code HTML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| <!DOCTYPE html>
<html >
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<meta name="viewport" content=" width=device-width, initial-scale=1, shrink-to-fit=no" charset="utf-8">
<title>bootstrap</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link href="exemple.css"; rel="stylesheet" >
</head>
<body >
<div class=" wrapper ">
<!--sidebar-->
<nav id="sidebar" >
<div class="sticky-top">
<div style="height: 57px;" class="sticky-top sidebar-header">
<h4>SIDEBAR</h4>
</div>
</div>
</nav>
<!-- contenu -->
<div class="w-100 ">
<nav class="sticky-top navbar navbar-expand-lg navbar-dark bg-dark pt-3 pb-0 ">
<div class="w-100 container-fluid">
<button type="button" id="sidebarCollapse" class="btn btn-light " data-target="#sidebar" >
<i class="fas fa-align-left"></i>
<span></span>
<span></span>
<span></span>
</button>
<a class="ml-2 text-capitalize font-weight-bold pl-2 navbar-brand" href="../boot.html">SIDEBAR </a>
<div class="collapse navbar-collapse" id="navbarText">
<div class="ml-5 dropdown">
<a class=" btn btn-sm btn-secondary dropdown" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu principal
</a>
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
<script >
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#sidebar').toggleClass('active');
});
});
</script>
</html> |
et le CSS si besoin :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| nav {
border-bottom : 1px black solid;
-webkit-box-shadow: 1px 2px 5px 1px rgba(186,186,186,0.91);
box-shadow: 1px 2px 5px 1px rgba(186,186,186,0.91);
}
/* sidebar */
.wrapper {
display: flex;
width: 100%;
align-items: stretch;
}
#sidebar {
min-width: 250px;
max-width: 250px;
}
#sidebar.active {
margin-left: -250px;
}
#sidebar {
min-width: 250px;
max-width: 250px;
min-height: 100vh;
}
a[data-toggle="collapse"] {
position: relative;
}
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}
@media (max-width: 768px) {
#sidebar {
margin-left: -250px;
}
#sidebar.active {
margin-left: 0;
}
}
@import "https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700";
body {
font-family: 'Poppins', sans-serif;
background: #fafafa;
}
p {
font-family: 'Poppins', sans-serif;
font-size: 1.1em;
font-weight: 300;
line-height: 1.7em;
color: #999;
}
a, a:hover, a:focus {
color: inherit;
text-decoration: none;
transition: all 0.3s;
}
#sidebar {
/* don't forget to add all the previously mentioned styles here too */
background: #566573 ;
color: #fff;
transition: all 0.6s;
}
#sidebar .sidebar-header {
padding: 20px;
background: #343a40 ;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #47748b;
}
#sidebar ul p {
color: #fff;
padding: 10px;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #566573;
background: #fff;
}
#sidebar ul li.active > a, a[aria-expanded="true"] {
color: #fff;
background: #343a40 ;
}
ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #343a40 ;
} |
Merci d'avance !