If you want to create a responsive menu for your website, you'll need to incorporate some javascript. I found a great example on w3schools that demonstrates how to achieve this. You can check out the full tutorial here.
The process involves hiding the menu on mobile devices using media queries, adjusting its style, and then revealing it with javascript.
JavaScript is required to enable the menu dropdown toggle functionality, while CSS takes care of the rest.
Feel free to ask any questions in the comments section.
/* JavaScript function to toggle the "responsive" class for topnav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
/* CSS styling for the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Styling for links within the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Link hover effects */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Hide the nav icon on small screens */
.topnav .icon {
display: none;
}
/* Responsive design for small screens */
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
<div class="topnav" id="myTopnav">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">☰</a>
</div>