<nav>
<a href="#" class="logo">Logo</a>
<!--Links-->
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li>
<a href="#" id="services-link">Services <i class="fas fa-caret-down"></i></a>
<div class="dropdown">
<ul>
<li><a href="#">Reviews</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">FAQs</a></li>
</ul>
</div>
</li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
@charset "utf=8";
@import url("https://fonts.googleapis.com/css2?family=Asap&family=Roboto:ital,wght@0,500;0,900;1,500&display=swap");
* {
box-sizing: border-box;
scroll-behavior: smooth;
margin: 0px;
padding: 0px;
font-family: "Asap", sans-serif;
}
body{
background-color: #e0ffff;
}
a {
text-decoration: none;
color: #e0ffff;
font-size: 20px;
transition: 0.3s;
}
a:hover{
color: #00c2cb;
}
nav {
background: #22232e;
height: 80px;
width: 100%;
display: flex;
align-items: center;
justify-content: space-around;
padding: 0px 5%;
}
.logo{
color: #00c2cb;
font-size: 1.5rem;
}
nav ul{
display: flex;
list-style: none;
}
nav ul li{
padding: 10px 30px;
position: relative;
}
a:hover{
color: #00c2cb;
}
.dropdown{
display: none;
position: absolute;
left: 0;
top: 100%;
background-color: #22232e;
}
.dropdown ul{
display: block;
margin: 10px;
}
.dropdown ul li{
width: 150px;
padding: 10px;
}
/* Show the dropdown when hovering the services link */
.dropdown.active {
display: block;
}
const servicesLink = document.querySelector("#services-link");
const dropdownMenu = document.querySelector(".dropdown");
// Show/hide the dropdown when clicking the services link
servicesLink.addEventListener("click", function (event) {
event.preventDefault(); // prevent the link from being followed
dropdownMenu.classList.toggle("active");
});
This Pen doesn't use any external JavaScript resources.