I recently used W3Schools as a reference to create a sidenav overlay menu https://www.w3schools.com/howto/howto_js_sidenav.asp with an accordion feature https://www.w3schools.com/howto/howto_js_accordion.asp. Despite my efforts, I'm struggling to make it responsive.
I attempted using #menu to address the issue, but it resulted in the entire menu disappearing. I suspect that my links not being enclosed in ul or li elements might be causing this problem.
<header>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="index.html">Home</a>
<a class="accordion" href="#">Design ▿</a>
<div class="panel">
<a href="mobile.html">Mobile</a>
<a href="#">Web</a>
</div>
<a href="photography.html">Photography</a>
<a href="branding.html">Branding</a>
<a href="about.html">About | Contact</a>
</div>
<span class="opening" onclick="openNav()"><i class="fas fa-stream"></i></span>
</header>
.sidenav {
position: fixed;
width: 0;
height: 100%;
top: 0;
left: 0;
padding-top: 4rem;
z-index: 1;
transition: 0.5s;
overflow-x: hidden;
background-color: ghostwhite;
float: left;
}
.sidenav a {
display: block;
padding: 10px 10px 10px 32px;
transition: 0.3s;
font-size: 1rem;
font-family: mr-eaves-xl-modern,sans-serif;
font-weight: 300;
font-style: normal;
letter-spacing: 1.5px;
text-decoration: none;
text-align: left;
color: #504E4E;
}
.sidenav a:hover {
font-style: italic;
}
.opening {
position: absolute;
top: 1.5rem;
left: 5%;
font-size: 1.3rem;
color: #504E4E;
float: left;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 5%;
margin-left: 20%;
float: left;
}
.accordion {
width: 100%;
padding: 18px;
border: none;
outline: none;
transition: 0.4s;
font-size: 1rem;
text-align: left;
color: #504E4E;
}
.active .accordion:hover{
font-style: italic;
}
.panel {
max-height: 0;
padding: 0 18px;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: ghostwhite;
font-size: 1rem;
font-family: mr-eaves-xl-modern,sans-serif;
font-weight: 300;
font-style: normal;
letter-spacing: 1.5px;
text-decoration: none;
color: #504E4E;
}
My goal is to achieve a horizontal menu layout when viewed on desktop screens.