Change bootstrap navbar collapse breakpoint without using LESS
Currently when the browser width drops below 768px, the navbar changes to collapsed mode. I want to change this width to 1000px so when the browser is below 1000px the navbar changes to collapsed mode. I want to do this without using LESS, I am using stylus not LESS.
My issue is the same as in this question: Bootstrap 3 Navbar Collapse
But all the answers in that questions explain how to do it by changing LESS variable. I haven't been dealing with LESS, I am using stylus so I want to know how this can be done using stylus or another method.
Thanks!
You have to write a specific media query for this, from your question, below 768px, the navbar will collapse, so apply it above 768px and below 1000px, just like that:
@media (min-width: 768px) and (max-width: 1000px) {
.collapse {
display: none !important;
}
}
This will hide the navbar collapse until the default occurrence of the bootstrap unit. As the collapse class flips the inner assets inside navbar collapse will be automatically hidden, like wise you have to set your css as you desired design.
2018 UPDATE
Bootstrap 4
Changing the navbar breakpoint is easier in Bootstrap 4 using the navbar-expand-*
classes:
<nav class="navbar fixed-top navbar-expand-sm">..</nav>
navbar-expand-sm
= mobile menu on xs screens <576px navbar-expand-md
= mobile menu on sm screens <768px navbar-expand-lg
= mobile menu on md screens <992px navbar-expand-xl
= mobile menu on lg screens <1200px navbar-expand
= never use mobile menu (no expand class)
= always use mobile menu If you exclude navbar-expand-*
the mobile menu will be used at all
widths. Here's a demo of all 6 navbar states: Bootstrap 4 Navbar Example
You can also use a custom breakpoint (???px) by adding a little CSS. For example, here's 1300px..
@media (min-width: 1300px){
.navbar-expand-custom {
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
}
.navbar-expand-custom .navbar-nav {
flex-direction: row;
}
.navbar-expand-custom .navbar-nav .nav-link {
padding-right: .5rem;
padding-left: .5rem;
}
.navbar-expand-custom .navbar-collapse {
display: flex!important;
}
.navbar-expand-custom .navbar-toggler {
display: none;
}
}
Bootstrap 4 Custom Navbar Breakpoint
Bootstrap 4 Navbar Breakpoint Examples
Bootstrap 3
For Bootstrap 3.3.x, here is the working CSS to override the navbar breakpoint. Change 991px
to the pixel dimension of the point at which you want the navbar to collapse...
@media (max-width: 991px) {
.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;
}
}
Working example for 991px: http://www.bootply.com/j7XJuaE5v6
Working example for 1200px: https://www.codeply.com/go/VsYaOLzfb4 (with search form)
Note: The above works for anything over 768px. If you need to change it to less than 768px the example of less than 768px is here.
in bootstrap3 , change this variable @grid-float-breakpoint to the one you need. The default value is 768px
链接地址: http://www.djcxy.com/p/89462.html