如何在所有屏幕尺寸下保持 Bootstrap 3 导航栏折叠 [英] How to keep Bootstrap 3 navbar as collapsed for all screen sizes
问题描述
在引导程序 3 中,我希望导航栏默认为所有屏幕尺寸折叠.
In bootstrap 3, I want the navbar to be collapsed by default for all screen sizes.
我在这里发现 Bootstrap 3 首先是移动的,它的导航栏默认情况下是折叠"的,并且当它达到某个最小尺寸时展开".. 在那篇文章之后,我尝试使用 @grid-float-breakpoint
为 自定义 css,但我一无所获.请从这里引导我.
I have found here that Bootstrap 3 being mobile first, its navbar is "collapsed" by default and and "expands" when it reaches a certain minimum size.. Following that post, I tried messing around with @grid-float-breakpoint
for customized css, but I got nowhere. Please guide me from here.
推荐答案
您可以使用 CSS 来覆盖 Bootstrap 3 默认设置.例如,这会将导航栏设置为在小于 2000 像素的屏幕宽度上折叠(适用于大多数屏幕).
You could use CSS to override the Bootstrap 3 defaults. For example, this would set the navbar to collapse on screen widths less than 2000 pixels (accommodating most screens)..
@media (max-width: 2000px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
演示:http://www.bootply.com/122572
Bootstrap 4(测试版)更新
在 Bootstrap 4 中,导航栏在默认情况下总是折叠到移动版/汉堡版:演示.navbar-expand-*
类用于更改断点.
In Bootstrap 4 the navbar is always collapsed into the mobile/hamburger version by default: Demo. The navbar-expand-*
class are used to change the breakpoint.
这篇关于如何在所有屏幕尺寸下保持 Bootstrap 3 导航栏折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!