I have set the sub-menu to be hidden with display: none
, and it should show on hover with display: block
, but for some reason, it's not working as expected.
To make the sub-menu appear when hovering over main-menu-link
, you can use the following HTML and CSS:
.main-menu-link:link,
.main-menu-link:visited {
display: inline-block;
text-decoration: none;
color: #333;
font-weight: 600;
font-size: 1.8rem;
transition: all 0.3s;
}
.main-menu-link:hover,
.main-menu-link:active {
color: #e67e22;
}
.sub-menu {
list-style: none;
position: absolute;
width: 12%;
line-height: 1.5;
padding-top: 1rem;
display: none; /* hiding the sub menu */
background-color: #ddd;
}
.main-menu-link:hover .sub-menu {
display: block; /* showing the sub menu on hover */
}
<nav class="main-nav">
<ul class="main-nav-list">
<li><a class="main-nav-link" href="#introduction">Introduction</a></li>
<li><a class="main-nav-link" href="#product">Product</a></li>
<li>
<a class="main-menu-link" href="#">Facilities & processing</a>
<ul class="sub-menu">
<li><a class="sub-menu-link" href="#facilities">Facilities</a></li>
<li><a class="sub-menu-link" href="#processing">Processing </a></li>
</ul>
</li>
<li><a class="main-nav-link" href="#processing">Processing </a></li>
<li><a class="main-nav-link" href="#procurement-sales">Procurment & Sales</a></li>