I am faced with a challenge involving a lengthy navigation menu (.nav-main
) nested within a fixed header (header
). When the navigation menu is toggled using jQuery .toggle()
, the content extends beyond the window height and does not scroll. I am looking for a solution to add a scrollbar (ideally through CSS) to the child div within the fixed header:
<header class="clearfix">
<nav class="nav-main">
<button>Open Topics</button>
<ul>
<li><a href="">Section 1</a></li>
<li><a href="">Section 2</a></li>
<li><a href="">Section 3</a></li>
<li><a href="">Section 4</a></li>
<li><a href="">Section 5</a></li>
<li><a href="">Section 6</a></li>
<li><a href="">Section 7</a></li>
<li><a href="">Section 8</a></li>
<li><a href="">Section 9</a></li>
<li><a href="">Section 10</a></li>
<li><a href="">Section 11</a></li>
<li><a href="">Section 12</a></li>
<li><a href="">Section 13</a></li>
<li><a href="">Section 14</a></li>
<li><a href="">Section 15</a></li>
<li><a href="">Section 16</a></li>
<li><a href="">Section 17</a></li>
<li><a href="">Section 18</a></li>
<li><a href="">Section 19</a></li>
<li><a href="">Section 20</a></li>
</ul>
</nav><!--end nav-main-->
</header>
<div id="main">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div><!--end main-->
The SCSS/CSS:
header{
background-color: #ccc;
position: fixed;
top: 0;
left: 0;
width: 100%;
.head-wrap{
position: relative;
height: 50px;
}
.nav-main{
position: relative;
button{
float: right;
margin-top: 10px;
margin-right: 70px;
background-color: pink;
}
ul{
display: none;
background-color: #333;
top: 50px;
position: absolute;
width: 100%;
z-index: 2;
overflow: auto;
li{
background-color: #333;
a{
color: #fff;
text-decoration: none;
padding:10px 50px;
display: block;
}
}
}
}
}
#main{
margin-top: 50px;
p{
margin-bottom: 20px;
}
}
And my .toggle()
JS:
$(".nav-main button").click(function(event){
$(".nav-main ul").toggle();
event.preventDefault();
});
If you have any tips or solutions, please let me know. Thank you!