So im following bootstrap sidebar tutorial from this site: https://bootstrapious.com/p/bootstrap-sidebar and im making a very simple one by following very first static sidebar he made. Problem is in CSS when i use .active
without #sidebar
the button works, but on his code he used #sidebar .active
together in CSS and his button works too on mine is opposite it wont work unless i use .active
alone. Why is this the case?
Here’s my HTML :
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Page</title>
<link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" media="screen" href="Testing.css">
</head>
<body>
<div id="wrapper">
<div id="sidebar">
<ul>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
</ul>
</div>
<div class="content">
<button id="toggleButton">Click</button>
<p>Loren ipsum text hahha ogbjgirtj njgnbjkg kgjbhmgogj</p>
</div>
</div>
<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.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<script src="Testing.js"></script>
</body>
</html>
CSS:
#wrapper {
display: flex;
align-items: stretch;
}
#sidebar {
width: 250px;
height: 100vh;
background: #8f8fd3;
transition: all 0.3s;
}
#sidebar .active {
margin-left: -250px;
}
JavaScript(JQuery):
$(document).ready( function() {
$("#toggleButton").on("click", function () {
$("#sidebar").toggleClass("active");
});
});
EDIT: Nvm i i wasnt supposed to use space between id and class. Problem solved.