<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manipulating CSS Classes</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="./style.css">
</head>

<body>

    <nav>
        <button class="nav-toggle">
            <i class="fa fa-navicon"></i>
        </button>
        <aside class="nav-sidebar">
            <div class="nav-header">
                <button class="nav-close">
                    <i class="fa fa-times"></i>
                </button>
            </div>
            <ul class="links">
                <li>
                    <a href="#">Home</a>
                </li>
                <li>
                    <a href="#">About</a>
                </li>
                <li>
                    <a href="#">Services</a>
                </li>
                <li>
                    <a href="#">Contact</a>
                </li>
            </ul>
        </aside>
    </nav>
    <script src="./app.js"></script>
</body>

</html>
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: aqua;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}

a {
    text-decoration: none;
    color: black;
}

li {
    list-style-type: none;
}

button {
    border: transparent;
    background-color: transparent;
    font-size: 25px;
}

button:hover {
    transition: .5s ease-in-out;
    transform: rotate(360deg);
    color: rgb(214, 211, 16);
}

.nav-toggle {
    position: absolute;
    right: 0;
    top: 0;
    margin: 20px;
}

.nav-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 350px;
    background-color: #fff;
    transform: translate(-100%);
    transition: .5s ease-in-out;
}

@media (max-width:800px) {
    .nav-sidebar {
        width: 100%;
    }
}

.show-sidebar {
    transition: .5s ease-in-out;
    transform: translate(0);
}

.nav-header {
    position: absolute;
    right: 0;
    top: 0;
    margin: 20px;
}

.links {
    margin-top: 70px;
}

li {
    padding: 10px 20px;
    transition: .5s ease-in;
}

li:hover {
    background-color: aqua;
    transition: .5s ease-out;
    transform: translate(20px);
}

a:hover {
    color: #fff;
}
const navToggle = document.querySelector('.nav-toggle');
const navClose = document.querySelector('.nav-close');
const navSidebar = document.querySelector('.nav-sidebar');

navToggle.addEventListener("click", () => {
  
    // if (navSidebar.classList.contains('show-sidebar')) {
    //     navSidebar.classList.remove('show-sidebar');
    // } else {
    //     navSidebar.classList.add('show-sidebar');
    // }
  
  //using the toggle method
    navSidebar.classList.toggle('show-sidebar');
})

navClose.addEventListener("click", () => {
    navSidebar.classList.remove('show-sidebar');
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.