目前,当浏览器宽度降至768px以下时,.navbar
会更改为折叠模式。我想将此宽度更改为992px,因此当浏览器低于992px时,.navbar
会更改为折叠模式..我正在使用bootstrap 3.3.6
我正在使用此代码,但它对我不起作用
@media screen and (max-width: 992px) {
.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;
}
}
答案 0 :(得分:4)
我正在寻找完全相同的东西,我发现this,它100%有效!
您需要添加此css
@media (max-width: 992px) {
.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;
}
}
你还需要这个javascript
$('#monitor').html($(window).width());
$(window).resize(function() {
var viewportWidth = $(window).width();
$('#monitor').html(viewportWidth);
});
如果不起作用,请回答我这些问题......
看看我的HTML代码,它可能对你有帮助......
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- This is the main nav menu content -->
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav hover-effect">
<li><a href="#header">Home</a></li>..........
答案 1 :(得分:0)
推荐的方法是使用Bootstrap&#39; Customize and download&#39;用于根据您的要求自定义Bootstrap。
或者您可以更改媒体查询,但最终可能会覆盖一堆类:
@media (min-width: 768px) and (max-width: 992px) {
.collapse {
display: none !important;
}
}
答案 2 :(得分:0)
这样可行,导航栏以992px折叠,下面是css代码:
@media (min-width: 992px) {
.navbar-right .dropdown-menu {
left: auto;
right: 0;
}
.navbar-right .dropdown-menu-left {
left: 0;
right: auto;
}
}
@media (min-width: 992px) {
.navbar-header {
float: left;
}
}
@media (min-width: 992px) {
.navbar-collapse {
width: auto;
border-top: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.navbar-collapse.collapse {
display: block !important;
height: auto !important;
padding-bottom: 0;
overflow: visible !important;
}
.navbar-collapse.in {
overflow-y: visible;
}
.navbar-fixed-top .navbar-collapse,
.navbar-static-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
padding-left: 0;
padding-right: 0;
}
}
@media (min-width: 992px) {
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: 0;
margin-left: 0;
}
}
@media (min-width: 992px) {
.navbar-fixed-top,
.navbar-fixed-bottom {
border-radius: 0;
}
}
@media (min-width: 992px) {
.navbar-fixed-top,
.navbar-fixed-bottom {
border-radius: 0;
}
}
@media (min-width: 992px) {
.navbar > .container .navbar-brand,
.navbar > .container-fluid .navbar-brand {
margin-left: -15px;
}
}
@media (min-width: 992px) {
.navbar-toggle {
display: none;
}
}
@media (min-width: 992px) {
.navbar-nav {
float: left;
margin: 0;
}
.navbar-nav > li {
float: left;
}
.navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
}
@media (min-width: 992px) {
.navbar-form {
width: auto;
border: 0;
margin-left: 0;
margin-right: 0;
padding-top: 0;
padding-bottom: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
}
@media (min-width: 992px) {
.navbar-text {
float: left;
margin-left: 15px;
margin-right: 15px;
}
}
@media (min-width: 992px) {
.navbar-left {
float: left !important;
}
.navbar-right {
float: right !important;
margin-right: -15px;
}
.navbar-right ~ .navbar-right {
margin-right: 0;
}
}
答案 3 :(得分:0)
我在bootstrap 3.3.6中尝试了以下代码并且它可以工作。
@media (max-width: 996px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
}
请检查此jsfiddle