Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot scroll down a collapsed navbar on mobile devices #23374

Closed
clheppell opened this issue Aug 12, 2017 · 27 comments · Fixed by #32037
Closed

Cannot scroll down a collapsed navbar on mobile devices #23374

clheppell opened this issue Aug 12, 2017 · 27 comments · Fixed by #32037

Comments

@clheppell
Copy link

clheppell commented Aug 12, 2017

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.

@tmorehouse
Copy link
Contributor

One quick fix:

.navbar-collapse {
  max-height: 280px;
  overflow-y: auto;
}

or (but not all browsers support vh units):

.navbar-collapse {
  max-height: 0.9vh;
  overflow-y: auto;
}

@jacqueslareau
Copy link

@tmorehouse While this seems to fix the issue in mobile, it seems to create an issue with dropdowns when in full width.

image

@tmorehouse
Copy link
Contributor

Might need a few tweaks to the selector to target just when the collapse is opened:

.navbar-collapse.collapse.show {
  max-height: 280px;
  overflow-y: auto;
}

@jacqueslareau
Copy link

Thanks it looks like it is "working". But just want to point out that when you resize the browser back to full screen while the collapsed menu is opened, it does the same thing. Looks like the show class is not being cleared. Sorry I don't have time to dig into this. :(

@tmorehouse
Copy link
Contributor

Probably placing this CSS in a media query, based on the breakpoint used in navbar, would control when this rule is applied.

@marcosnakamine
Copy link

nav.navbar.fixed-top {
    max-height:100%;
    overflow-y:auto;
}

@clheppell
Copy link
Author

clheppell commented Aug 24, 2017

A max-height: 100% approach does not work because of the height of the fixed navbar at the the top of the screen, which must be discounted

@s4uron
Copy link

s4uron commented Sep 15, 2017

nav.navbar.fixed-top {
    max-height: 100%;
    overflow-y: auto;
}

@media (min-width: 992px) {
    nav.navbar.fixed-top {
        overflow-y: visible;
    }
}

works for me. If you have another mobile / desktop breakpoint change the media value.

@milossumic
Copy link

.navbar-collapse { max-height: calc(100vh - 60px); overflow-y: auto; }

Try this

@Dygear
Copy link

Dygear commented Jul 6, 2018

@milossumic's comment on Apr 13th fixed the scrolling issue for me and then broke the drop down menu in the desktop version ...

@s4uron's comment on Sep 15, 2017 did fix the issues on mobile devices while not breaking anything extra on the desktop side of things.

@milossumic
Copy link

milossumic commented Jul 9, 2018

@Dygear You should put it in media query and use it only for smaller screens that you need. Then it won't break on desktop.

@Wruczek
Copy link

Wruczek commented Sep 4, 2018

Fix as of Bootstrap 4.1:

@media (max-width: 991px) {
    .navbar {
        overflow: auto;
        max-height: 85vh;
        align-items: flex-start;
    }
}

@danielmarsch
Copy link

I was desperatly searching for a fix for exactly this problem. Thank you so much!

@brass-machine
Copy link

@danielmarsch This isn't 100% reliable, it can break the desktop version in certain situations.

@milossumic
Copy link

@danielmarsch This isn't 100% reliable, it can break the desktop version in certain situations.

Use it only on the screen sizes that you need.

@brass-machine
Copy link

brass-machine commented Nov 21, 2018

It would be beneficial to get this fix incorporated at some point so anyone could use BootstrapCDN without having to make custom modifications..

@adriandmitroca
Copy link

adriandmitroca commented Dec 5, 2018

#23374 (comment)

unset isn't too well supported by browsers, the fix should look more like this:

.navbar {
  @media (max-width: breakpoint-max(md)) {
    overflow: auto;
    max-height: 85vh;
    align-items: start;
  }
}

@maugithuber
Copy link

it really works for me thx

@Muetze42
Copy link

Muetze42 commented May 24, 2019

For all navbars:

  @media (max-width: 576px) {
    .navbar-collapse {
      max-height: calc(100vh - 125px);
      overflow-y: auto;
    }
  }
}
navbar-expand-md {
  @media (max-width: 768px) {
    .navbar-collapse {
      max-height: calc(100vh - 125px);
      overflow-y: auto;
    }
  }
}
navbar-expand-lg {
  @media (max-width: 992px) {
    .navbar-collapse {
      max-height: calc(100vh - 125px);
      overflow-y: auto;
    }
  }
}
navbar-expand-xl {
  @media (max-width: 1200px) {
    .navbar-collapse {
      max-height: calc(100vh - 125px);
      overflow-y: auto;
    }
  }
}

@ChooChu
Copy link

ChooChu commented Jul 10, 2019

try this it work for me :D

`
@media screen and (max-width: 1000px) {
.navbar-collapse {
max-height: calc(100vh - 60px);
overflow-y: auto;
}
}

`

@domidevelop
Copy link

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.

.navbar-collapse {
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.collapsing {
  overflow-y: hidden;
  overflow-x: hidden;
}

@parisiam
Copy link

I've sassed @NormanHuth solution:

@each $name, $width in $grid-breakpoints {
    @if $width != 0 {
        @media (max-width: #{$width}) {
            .navbar-expand-#{$name}.fixed-top .navbar-collapse {
                max-height: calc(100vh - 125px)
                overflow-y: auto;
            }
        }
    }
}

@Muetze42
Copy link

Muetze42 commented Nov 1, 2020

I've sassed @NormanHuth solution:

The 125px depends on how big your navbar is.

@mdo
Copy link
Member

mdo commented Nov 1, 2020

Rather than add responsive classes for this, I'm wondering how folks would feel about a .navbar-nav-scroll class that adds a CSS custom property with a fallback default value. See #32037 for what I mean.

@clheppell
Copy link
Author

That looks like a good solution to this.

I think my only thought UI wise is how to make it clear that it's scrollable.

@mdo mdo added the v5 label Jan 10, 2021
@mdo mdo added this to Inbox in v5.0.0-beta2 via automation Jan 10, 2021
@mdo mdo added the has-pr label Jan 10, 2021
@UtopieStudio
Copy link

UtopieStudio commented Jan 17, 2021

THIS is the only solution which worked for me after trying MANY other solutions (BS 4.5.2). For anyone whose IDE doesn't catch it, there seems to be an erroneous closing bracket on @NormanHuth 's first CSS query? Thank you, thank you!!

@XhmikosR XhmikosR added this to Inbox in v4.6.0 Jan 19, 2021
v5.0.0-beta2 automation moved this from Inbox to Done Jan 19, 2021
@XhmikosR XhmikosR moved this from Inbox to Shipped in v4.6.0 Jan 19, 2021
@hasse-basse
Copy link

Wruczek

Wonderful, thanks!

Tested on 5.0.2 and 5.1.3 without any problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v4.6.0
Shipped
v5.0.0-beta2
  
Done
Development

Successfully merging a pull request may close this issue.