<button id="btn">☰</button>
<nav id="nav">
<ul>
<li><a href="#">Google</a></li>
<li><a href="#">Youtube</a></li>
<li><a href="#">Instagram</a></li>
<li><a href="#">Facebook</a></li>
</ul>
</nav>
* {
box-sizing: border-box;
}
body {
background-color: #fff;
color: #000;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
margin: 0;
min-height: 100vh;
}
button {
background-color: #000;
border: none;
color: white;
position: fixed;
top: 20px;
right: 20px;
padding: 1rem;
transition: transform 0.3s ease-in-out;
}
button.active {
transform: translateX(-197px);
}
nav {
background-color: #000;
position: fixed;
top: 0;
right: 0;
height: 100vh;
padding: 2rem;
transform: translateX(100%);
transition: transform 0.3s ease-in-out;
}
nav.active {
transform: translateX(0);
}
nav ul {
padding: 0;
list-style-type: none;
margin: 0;
}
nav ul li {
padding: 2rem 0;
}
nav a {
color: white;
text-decoration: none;
}
const btn = document.getElementById('btn');
const nav = document.getElementById('nav');
btn.addEventListener("click", () => {
nav.classList.toggle("active");
btn.classList.toggle("active");
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.