Layout:
<body> <nav> <button> <div class="container"> <ul></ul> </div> </nav> </body> Styles:
nav { position: relative; z-index: 4; } body.fix-nav nav { position: fixed; top: 32px; } .container { position: absolute; z-index: -1; top: 0px; right: 0; overflow: auto; background: #000; } nav is a common navigation block. When scrolling the page comes to it, the fix-nav class is added to the body element via javascript. And, accordingly, the nav fixed at the top of the screen.
button - the menu open / close button
.container - a container for the menu, attached to the nav .
ul - the menu itself
When nav fixed on top of the screen, the menu is there. And when scrolling has not yet reached navigation, the menu is fixed relative to the nav position.
The problem is that I need to implement a vertical scrolling menu. And for this I need to make the element .container equal to the height of the screen minus the position of the nav (so that nothing goes beyond the edges of the screen) - when the nav not fixed.
I tried to use position: fixed for .container , but it turns out crooked. Especially because nav can be both relative and fixed. It would be possible to implement this in JavaScript, but it seems to me that it would be irrational from the point of view of performance.