Mon Jul 17 2023
Sliding Menu Bar
CSS202 views
File Name: creating-a-sliding-menu-bar-with-html-and-css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap" rel="stylesheet">
<title>Sliding Menubar</title>
<style>
:root {
--blue: #0087EB;
--white: #fff;
--purple: #4D2B89;
--lightPurple: #683AB7;
--gray: #2b2b2b;
}
* {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
.container {
width: 98%;
max-width: 1100px;
margin: 0 auto;
}
header {
background-color: var(--purple);
padding: 10px 0;
}
header div.container {
display: flex;
justify-content: space-between;
align-items: center;
}
header a#menuBtn {
border: var(--white) solid thin;
border-radius: 3px;
padding: 5px;
display: flex;
justify-content: center;
cursor: pointer;
}
header a#menuBtn svg {
width: 25px;
height: 18px;
}
header a#menuBtn svg rect {
fill: var(--white);
}
header a.btn {
text-decoration: none;
background-color: var(--lightPurple);
color: var(--white);
padding: 5px 20px;
border-radius: 20px;
font-weight: 400;
}
nav#menuBar {
position: fixed;
top: 0;
bottom: 0;
left: -300px;
width: 200px;
transition: 0.3s all ease-in-out;
background-color: var(--lightPurple);
overflow: hidden;
box-shadow: 0 2px 3px 1px var(--gray);
transition-delay: 0.5s;
}
nav#menuBar.active {
left: 0;
transition-delay: 0s;
}
nav#menuBar ul {
padding: 0 20px;
margin: 0;
list-style: none;
}
nav#menuBar ul li {
margin: 20px 0;
transform: translateX(-100%);
transition: 0.3s all ease-in-out;
transition-delay: calc(0.1s * var(--i));
}
nav#menuBar.active ul li {
transform: translateX(0);
transition-delay: calc(0.2s * var(--i));
}
nav#menuBar ul li a {
color: var(--white);
text-decoration: none;
font-size: 18px;
}
</style>
<script>
const toggleMenu = ()=> {
const menuBar = document.getElementById("menuBar");
menuBar.classList.toggle('active');
}
</script>
</head>
<body>
<header>
<div class="container">
<a onclick="toggleMenu()" id="menuBtn">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 246.42 246.04"><rect x="0.53" y="30.22" width="245.37" height="22.38"/><rect x="0.53" y="111.81" width="245.37" height="22.38"/><rect x="0.53" y="193.4" width="245.37" height="22.38"/></svg>
</a>
<nav>
<a href="" class="btn">Sign Up</a>
</nav>
</div>
</header>
<nav id="menuBar">
<ul>
<li style="--i:1"><a href="">Dashboard</a></li>
<li style="--i:2"><a href="">Product</a></li>
<li style="--i:3"><a href="">Order List</a></li>
<li style="--i:4"><a href="">Analytics</a></li>
<li style="--i:5"><a href="">Settings</a></li>
</ul>
</nav>
</body>
</html>
Author:Geekboots