Hello guys, we are going to be creating a humbuger button using html css and javascript.
we would create a folder in your desktop and open it on your text editor(vsCode etc)
when the folder is open on your vscode create a file index.html
and write the code below
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="menu_icon_box" id="myLInks" >
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
<div class="box">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Testimonials</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
- Remeber to link your css like this
<link rel="stylesheet" href="style.css">
Now we add our css crate a file style.css
Inside thestyle.css
we will start by stying the css
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100vh;
background-color: #284e95;
}
.menu_icon_box {
z-index: 2;
width: fit-content;
height: auto;
background-color: #fff;
margin: 30px;
position: absolute;
border-radius: 4px;
cursor: pointer;
}
.line1,
.line2,
.line3 {
width: 40px;
height: 4px;
margin: 10px 8px;
background-color: #000;
border-radius: 50px;
transition: 0.2s;
}
.active .line1 {
transform: translate(0px, 15px)rotate(45deg);
}
.active .line2 {
opacity: 0;
}
.active .line3 {
transform: translate(0px, -15px)rotate(-45deg);
}
.box {
width: fit-content;
height: 100vh;
background-color: #fff;
position: relative;
text-align: left;
z-index: 1;
opacity: 0;
left: -500px;
pointer-events: none;
transition: 0.3s;
}
nav {
padding-top: 100px;
}
nav ul {
margin: 0px 30px;
}
nav ul li {
list-style: none;
margin-bottom: 30px;
transition: 0.2s;
}
nav ul li:hover {
background-color: #c6c6c66f;
border-radius: 8px;
}
nav ul li a {
color: #000;
font-size: 28px;
padding: 10px 30px;
display:inline;
text-decoration: none;
}
.active_box {
opacity: 1;
left: 0px;
pointer-events: fill;
}
After styling it should look like this
Lets add our javaScript
- we create a file
script.css
and we add a link in the html below the code close the the body tag
<script src="script.js"></script>
*Lets Start *
let menu_icon_box = document.querySelector(".menu_icon_box");
let box = document.querySelector(".box");
//for making it click
menu_icon_box.onclick = function(){
menu_icon_box.classList.toggle("active");
box.classList.toggle("active_box");
}
**
output
**
- For any question, can message me or leave a comment
- If you want any more tutorial comments and i will make one for you -You can get this code on my codepen
Top comments (0)