bootstrap: Cannot scroll down a collapsed navbar on mobile devices
When visiting a site using a mobile device with a navbar with .fixed-top, if the opened navbar-collapse area runs beyond the end on the viewport vertically (due to lots of links etc), you cannot scroll down the the links at the bottom of the navbar as you can in Bootstrap 3.
When you do try to scroll, the body behind the navbar scrolls, with the navbar fixed in place.
This can be fixed by setting overflow-y: auto; and adding a max-height:Xpx to the .collapse.show class and allows you to scroll the navbar-collapse area.
This happens in (the ones I tested) major browsers (Safari, Chrome, both on the latest updates). I haven’t yet tried whether this fix breaks anything elsewhere.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 10
- Comments: 27 (4 by maintainers)
Commits related to this issue
- Fix bug: navbar 清單太長時,無法下拉到最下面 — committed to HackerSir/CheckIn by danny50610 6 years ago
.navbar-collapse { max-height: calc(100vh - 60px); overflow-y: auto; }Try this
Fix as of Bootstrap 4.1:
works for me. If you have another mobile / desktop breakpoint change the media value.
One quick fix:
or (but not all browsers support
vhunits):https://github.com/twbs/bootstrap/issues/23374#issuecomment-418539829
unsetisn’t too well supported by browsers, the fix should look more like this:For all navbars:
I am using this. It avoids horizontal scroll bar and browser default scroll bar while collapsing. You can play with desired vh height of the navbar.