I created a Navbar using Bootstrap code but I am facing an issue where the 'active' state is not being applied to the Navbar elements on my webpage.
I have been attempting to add and remove the active class on the Navbar elements, but I have been unable to solve the aforementioned problem. Can someone please assist me?
.navbar {
position: fixed;
top: 0px;
width: 100%;
}
.nav-menu {
padding: 0;
background-color: #000000;
opacity: 0.85;
height: 60px;
}
.nav-menu ul {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0px;
list-style: none;
}
.nav-menu a {
display: block;
position: relative;
font-size: 16px;
font-weight: 400;
font-family: "Poppins", sans-serif;
margin: 0 0px;
text-decoration: none;
}
.nav-menu a:hover {
color: #FFFFFF;
transition: 0.9s;
box-sizing: border-box;
}
.nav-menu a:hover:after {
transform: translateX(-50%) scaleX(1);
}
.nav-menu a:after {
content: "";
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%) scaleX(0);
transform-origin: 50% 50%;
width: 100%;
height: 2px;
background-color: #C72C41;
transition: transform 250ms;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-inverse navbar-fixed-top navbar-fixed-width" role="navigation"></div>
<nav class="navbar navbar fixed-top navbar-expand-sm nav-menu" id="nav">
<div class="container">
<a href="#" class="navbar-brand">\harsh_sharma/</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarid">
<span id="tc"><i class="fas fa-bars"></i></span>
</button>
<div class="collapse navbar-collapse" id="navbarid">
<ul class="nav navbar-nav text-center ml-auto">
<li class="nav-item active"><a class="nav-link" href="#header">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="#experience">Experience</a></li>
<li class="nav-item"><a class="nav-link" href="#projects">Projects</a></li>
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>