简体   繁体   English

Twitter Bootstrap Navbar菜单滚动

[英]Twitter Bootstrap Navbar menu scrolling

While using twitter bootstrap 3 , on mobile devices menu nabber has horizontal and veritcal scrollers. 在使用twitter bootstrap 3 ,在移动设备上菜单nabber具有水平和nabber滚动条。

It was not there with 2.3 and I couldn't figure out how to disable it and let the menu items extend to full without any scroll-bars. 它不存在于2.3并且我无法弄清楚如何禁用它并让菜单项扩展到完全没有任何滚动条。

This is new to Bootstrap 3. 这是Bootstrap 3的新功能。

The best way to do this would be to remove or comment out lines 52 and 53 in /less/navbar.less: https://github.com/twbs/bootstrap/blob/master/less/navbar.less#L52-53 (you can optionally remove line 59) and recompile bootstrap.less. 执行此操作的最佳方法是删除或注释/less/navbar.less中的第52行和第53行: https//github.com/twbs/bootstrap/blob/master/less/navbar.less#L52-53 (您可以选择删除第59行)并重新编译bootstrap.less。

If you can't recompile Bootstrap with a tool like CodeKit or Grunt, you'll want to write a media query in your css document that singles out and overwrites the .navbar-collapse class maybe like this: 如果你不能用CodeKit或Grunt这样的工具重新编译Bootstrap,你会想要在你的css文档中编写一个媒体查询来单独输出并覆盖.navbar-collapse类可能是这样的:

@media (max-width: 767px) {
   .navbar-collapse {
      max-height: auto;
      overflow-x: auto;
   }
}

I haven't actually tested that code above - as I was able to recompile. 我实际上没有测试过上面的代码 - 因为我能够重新编译。 You may have to include !important or something like that. 你可能必须包括!important或类似的东西。

这应该这样做(如果你遵守CSS 3.0规则)

 max-height: none;

To remove the vertical scrollbar, this bit of CSS worked. 要删除垂直滚动条,这一点CSS工作。 I did not have horizontal scrollbars. 我没有水平滚动条。

@media (max-width: 767px) {
   .navbar-collapse {
      max-height: none;
   }
}

I just ran into this myself... 我自己就碰到了这个......

Just absolutely position .navbar-default. 只是绝对定位.navbar-default。

The .navbar-collapse div is absolutely positioned and you need to "attach" it to a parent/ancestor element that is NOT statically positioned. .navbar-collapse div是绝对定位的,您需要将它“附加”到非静态定位的父/祖先元素。 So, I just added: 所以,我刚补充说:

.navbar-default {
    position: absolute;
}

Don't know about Bootstrap 4(which just had it's alpha released), but this seems to do the trick with the Bootstrap 3 nav. 不知道Bootstrap 4(它刚刚发布了alpha版本),但这似乎可以解决Bootstrap 3导航问题。 I've got a really lengthy nav, and now I can properly scroll down and see all nav items. 我有一个非常冗长的导航,现在我可以正确向下滚动并查看所有导航项目。

Another solution, in Boostrap 3.3.4, is adding the following to your CSS: Boostrap 3.3.4中的另一个解决方案是在CSS中添加以下内容:

/* No scrolling for collapsed menu */

.navbar-collapse.in {
    overflow: hidden;
    max-height: none !important;
    height: auto !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM