Why wont my code work?

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>
        <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">

        <div id="wrapper">
            <div id="sidebar">

            <div class="content">
                <button id="toggleButton">Click</button>
                <p>Loren ipsum text hahha ogbjgirtj njgnbjkg kgjbhmgogj</p>
        <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>


#wrapper {
    display: flex;
    align-items: stretch;

#sidebar {
    width: 250px;
    height: 100vh;
    background: #8f8fd3;
    transition: all 0.3s;

#sidebar .active {
    margin-left: -250px;


$(document).ready( function() {
    $("#toggleButton").on("click", function () {

EDIT: Nvm i i wasnt supposed to use space between id and class. Problem solved.

I see you’ve figured it out in your edit

If you come across a similar problem again in not yet understanding how css selectors work, I’d strongly suggest reading the MDN section on css selectors (first page starts here: https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Selectors )

It’s worth revising that section to know what the selector should like when targetting the specific element

1 Like