So I am working on a Sidenav for a mobile friendly website. I have a working, multi-level hoverable drop-down menu within the sidebar.
I would like for the dropdowns to push the links beneath them down like in an accordian menu, rather than overlapping said links.
I've seen other solutions, but I'm having trouble wrapping my head around them.
Thanks in advance for any help!
Here is my current code for the menu:
function openNav() {
document.getElementById("mySidenav").style.width = "20%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
body {
font-family: Centaur;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: black;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
.dropbtn {
background-color: transparent;
padding: 2%;
font-size: 100%;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown1 {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
min-width: 160px;
z-index: 1;
}
.dropdown-content1 {
display: none;
position: absolute;
right: 0;
min-width: 160px;
z-index: 1;
}
.dropdown-content1 a {
text-decoration: none;
display: block;
}
.dropdown-content a {
text-decoration: none;
display: block;
}
.dropdown1:hover .dropdown-content1 {
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div style="width: 15%" id="navtaner">
<a href="">Home</a>
<div class="dropdown">
<a class="dropbtn">Swords</a>
<div class="dropdown-content" style=" float: right; margin-right:-55%">
<a href="#">Museum Line</a>
<div class="dropdown1">
<a href="#">Next Generation</a>
<div class="dropdown-content1">
<a href="#">Roman Swords</a>
<a href="#">Viking Swords</a>
<a href="#">Medieval One-Handed Swords </a>
<a href="#">Medieval Hand and-a-half swords</a>
<a href="#">Medieval Two-Handed Swords</a>
<a href="#">Single-Edged Swords</a></div>
</div>
<a href="#">Squire Line</a>
<a href="#">Maestro Line</a>
<a href="#">Skirmish Line</a>
<a href="#">Special Edition</a>
</div>
</div>
<div class="dropdown">
<a class="dropbtn">About</a>
<div class="dropdown-content">
<a href="#">Albion News</a>
<a href="#">Albion Media</a>
<a href="#">Albion Story</a>
<a href="#">Testimonials</a>
<a href="#">References</a>
<a href="#">Gallary</a>
</div>
</div>
<a href="#">Order</a>
</div>
</div>
<span style="font-size:30px;cursor:pointer; float: right" onclick="openNav()">☰ MENU</span>