I have a rather long nav (.nav-main) as a child div within a fixed header (header). When the nav is displayed via jQuery .toggle(), the content is longer than the window and thus does not scroll. I am trying to figure out how I can apply a scrollbar (preferably in CSS) to the child div within the fixed nav:
<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();
});
Here is a fiddle. Please shrink the window small enough so that when the nav is displayed by clicking on the button, the content is cut off, wanting a scrollbar:
You need to set a
heightattribute to the .nav-menu ul element. This can be set statically or use a script to set it based on the window height.JSFiddle