My website's responsive menu changes based on screen resolution, but I encountered an issue. On mobile viewports, the sub items in the menu are displayed by default. I want them to only appear when the parent item is clicked. Currently, clicking the parent item shows/hides them correctly, but I want them to start hidden. The code snippet below illustrates my implementation:
<script>
// JavaScript code for toggling menu and sub-menu items
$(document).ready(function () {
// Code for toggle functionality
});
</script>
<style>
/* CSS styles for the menu */
@media (min-width: 768px) and (max-width: 979px) {
/* Media query specific styling */
}
@media (max-width: 767px) {
/* Media query specific styling */
}
@media (max-width: 480px) {
/* Custom styling for smaller viewports */
}
@media (max-width: 320px) {
/* Styling adjustments for tiny screens */
}
</style>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<!-- Link your CSS files here --!>
<link rel="stylesheet" href="mobile/css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="mobile/font-awesome/css/font-awesome.css" />
</head>
<body>
<form id="mainform" runat="server">
<div class="container">
<a id="touch-menu" class="mobile-menu" href="#"><i class="icon-reorder">AGROBIZSA</i></a>
<nav>
<ul class="menu">
<li><a href="#"><i class="icon-home"></i>Inicio</a></li>
<li><a id="sub-menu-anchor-1" href="#"><i class="icon-user"></i>Noticias</a>
<ul id="sub-menu-1" class="sub-menu">
<li><a href="#">Últimas Noticias</a></li>
<li><a href="#">Noticias Corporativas</a></li>
<li><a href="#">Ecoambiental</a></li>
<li><a href="#">Agropecuaria</a></li>
<li><a href="#">Innovación</a></li>
<li><a href="#">Agronomía</a></li>
<li><a href="#">Salud</a></li>
</ul>
</li>
<li><a id="sub-menu-anchor-2" href="#"><i class="icon-camera"></i>eBooks</a>
<ul id="sub-menu-2" class="sub-menu">
<li><a href="#">Sanidad Vegetal</a></li>
<li><a href="#">Medio Ambiente</a></li>
<li><a href="#">Social</a></li>
<li><a href="#">Suelos y Agua</a></li>
<li><a href="#">Producción Agrícola</a></li>
<li><a href="#">Gestión</a></li>
</ul>
</li>
<li><a href="#"><i class="icon-bullhorn"></i>Hoy en la Historia</a></li>
<li><a href="#"><i class="icon-envelope-alt"></i>Eventos</a></li>
</ul>
</nav>
</div>
<div class="container">
<asp:ContentPlaceHolder ID="empaquetador" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>