Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Navigation Menu Bar" project using HTML, CSS & JavaScript.
Preview
In the above video, you’ve seen the preview of the "Navigation Menu Bar" project and I hope now you are able to create this type of project. If not, I have provided all the HTML CSS, and JavaScript code below.
Navigation Menu Bar [Source Code]
To get the following HTML, CSS & JS code for the Navigation Menu Bar project. You need to create three files one is an HTML file, the second one is a CSS file and another one is a JS file. After creating these three files then you can copy-paste the given codes on your document.
Remember, you’ve to create a file with a .html extension for HTML code, a .css extension for CSS code, and .js for JavaScript code.
You can also download all source code files from the given download button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Navigation Menu Bar</title>
<link rel="stylesheet" href="style.css">
<!-- Font awesome cdn -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="container">
<h1>Navigation Menu Bar</h1>
<ul class="allItems">
<li class="item">
<i class="fa-solid fa-house"></i>
<div class="title">Home</div>
</li>
<li class="item active">
<i class="fa-solid fa-address-card"></i>
<div class="title">About</div>
</li>
<li class="item">
<i class="fa-solid fa-toolbox"></i>
<div class="title">Services</div>
</li>
<li class="item">
<i class="fa-brands fa-blogger"></i>
<div class="title">Blog</div>
</li>
<li class="item">
<i class="fa-solid fa-headset"></i>
<div class="title">Contact</div>
</li>
<div class="dot"></div>
</ul>
</div>
<script src="index.js"></script>
</body>
</html>
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
background: white;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
min-height: 100vh;
}
h1 {
margin-bottom: 20px;
}
.allItems {
position: relative;
width: 600px;
height: 100px;
list-style: none;
color: white;
background-color: blueviolet;
border-radius: 50px;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.4s ease-in-out;
}
.item {
width: 100px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
cursor: pointer;
transition: all 0.4s ease-in-out;
}
.item.active {
transform: translateY(-10px);
}
.item i {
font-size: 30px;
}
.item .title {
font-size: 12px;
margin-bottom: -25px;
opacity: 0;
}
.item.active .title {
opacity: 1;
}
.dot {
width: 40px;
height: 40px;
border: 9px solid white;
border-radius: 50%;
background-color: blueviolet;
position: absolute;
left: 80px;
top: -20px;
transition: all 0.3s ease-in-out;
}
.dot::after,
.dot::before {
content: "";
width: 22px;
height: 22px;
position: absolute;
bottom: -11px;
background-color: blueviolet;
box-shadow: 0px -7px white;
}
.dot::after {
left: -24px;
border-top-right-radius: 25px;
}
.dot::before {
right: -24px;
border-top-left-radius: 25px;
}
const itemEls = document.querySelectorAll(".item");
itemEls.forEach((event,index) => {
event.addEventListener("click",()=>{
// remove previous active class and adding active class to user clicked icon.
document.querySelector(".active").classList.remove("active")
event.classList.add("active");
// moving dot to the place of active class icon
const dotEl = document.querySelector(".dot");
dotEl.style.left = `${index*100 + 80}px`
})
});
