I am coding an HTML page where I've incorporated CSS for the styling. However, I'm facing an issue with the drop-down menu. Whenever I try to click on a drop-down option, it disappears. How can I fix this?
I want the drop-down options to be clickable, organized in categories, and function properly. What am I missing in my code?
#mid ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
/*Creating a horizontal list with spacing*/
#mid li {
display: inline-block;
float: left;
margin-right: 1px;
}
/*Styling the menu links*/
#mid li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover effect for top-level links*/
#mid li:hover a {
background: #19c589;
}
/*Styling for drop-down links*/
#mid li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover effect for drop-down links*/
#mid li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hiding the dropdown links initially*/
#mid li ul {
display: none;
}
/*Making the drop-down links vertical*/
#mid li ul li {
display: block;
float: none;
}
/*Preventing text wrapping*/
#mid li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Displaying the dropdown on hover*/
#mid ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Styling the 'show menu' label button and hiding it by default*/
#mid .show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hiding the checkbox*/
#mid input[type=checkbox] {
display: none;
}
/*Showing the menu when the invisible checkbox is checked*/
#mid input[type=checkbox]:checked~#menu {
display: block;
}
<div id="mid">
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li><a href="#">Home</a></li>
<li>
<a href="#">Categories ↓</a>
<ul class="hidden">
<li><a href="#">Engineering </a></li>
<li><a href="#">MBA</a></li>
<li><a href="#">AGRICULTURE</a></li>
<li><a href="#">ARCHITECTURE</a></li>
<li><a href="#">Commerce</a></li>
<li><a href="#">Science</a></li>
<li><a href="#">PHD</a></li>
<li><a href="#">Other Branches</a></li>
</ul>
</li>
<li><a href="#">NOVELS</a>
</li>
<li><a href="#">News Updates</a></li>
<li>
<a href="#">Follow us ↓ </a>
<ul class="hidden">
<li><a href="#">Facebook</a></li>
<li><a href="#">Instagram</a></li>
<li><a href="#">Twitter</a></li>
</ul>
</li>
<li><a href="#">Contact Us ↓ </a>
<ul class="hidden">
<li><a href="#">ADVERTISEMENT</a></li>
<li><a href="#">Report Bug</a></li>
</ul>
</li>
</ul>
</div>
</html>