Navbar
Navbar
function updateIndicatorPosition(item) {
const itemRect = item.getBoundingClientRect();
const ulRect = document.querySelector('.nav-
ul').getBoundingClientRect();
indicator.style.width = `${itemRect.width}px`;
indicator.style.left = `${itemRect.left - ulRect.left}px`;
}
updateIndicatorPosition(activeItem);
navItems.forEach(item => {
item.addEventListener('click', () => {
document.querySelector('.nav-
item.active').classList.remove('active');
item.classList.add('active');
updateIndicatorPosition(item);
});
});
window.addEventListener('resize', () => {
const currentActive = document.querySelector('.nav-item.active');
updateIndicatorPosition(currentActive);
});
});
</script>
<!-- end navigation bar -->
CSS
/* NAVBAR */
.nav-wrapper {
background-color: #7BC9FF;
width: 91vw;
height: 11vh;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 4vw;
color: aliceblue; /* Default color for text */
}
.nav-wrapper:hover {
scale: 102%;
}
.logo {
width: 8vw;
height: auto;
margin-top: 1.8vh;
cursor: pointer;
}
.logo img {
width: 100%;
height: auto;
margin-top: 1vh;
}
.nav-ul {
display: flex;
list-style: none;
padding: 0;
margin: 0;
position: relative;
}
.nav-ul li {
transition: transform 0.3s ease;
}
.nav-ul li:hover {
transform: translateY(-1vh);
}
.nav-item {
position: relative;
padding: 10px;
cursor: pointer;
}
/* Link styles */
.nav-ul a {
text-decoration: none; /* Remove underline */
color: inherit; /* Ensure link color inherits from nav-item */
}
.account-img {
width: 3.4vw;
height: 7vh;
border-radius: 50%;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
.account-img img {
width: 100%;
height: auto;
}
.indicator {
position: absolute;
height: 5px;
background-color: #FF6F61;
border-radius: 10px;
bottom: 0;
transition: all 0.3s ease;
}
/* END NAVBAR */