1

Currently when the browser width drops below 768px, the .navbar changes to collapsed mode. I want to change this width to 992px so when the browser is below 992px the .navbar changes to collapsed mode.. I am using bootstrap 3.3.6

I am using this code but it doesn't work for me

@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;
}
}
Tasos K.
  • 7,979
  • 7
  • 39
  • 63
kev
  • 19
  • 1
  • 1
  • 6
  • What does "it doesnt work for me" actually mean because the above code does accomplish what your question asks. – vanburen Dec 27 '15 at 11:56
  • yes, but it doesn't work in my project, i don't know why – kev Dec 28 '15 at 23:42
  • 1
    Then you should take the time to post the relevant code (HTML, etc) and any other info concerning the environment you're working in. – vanburen Dec 28 '15 at 23:45

4 Answers4

6

I was looking for exactly the same thing and I found this , It works 100%!

You need to add this 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;
}
}

Also you need this javascript

$('#monitor').html($(window).width());

    $(window).resize(function() {
    var viewportWidth = $(window).width();
$('#monitor').html(viewportWidth);
});

If it doesn't work, answer me those questions...

  1. Do you use navbar-fixed-top ?
  2. Do you use navbar-inverse?

Take a look at my html code it might help you...

    <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>..........
BigDropGR
  • 344
  • 2
  • 11
0

The recommended approach is to use Bootstrap's 'Customize and download' function to customize Bootstrap to your requirement.

Alternatively you could change your media query, but you might end up overriding a bunch of classes:

@media (min-width: 768px) and (max-width: 992px) {
   .collapse {
       display: none !important;
   }
}
sjokkogutten
  • 2,005
  • 2
  • 21
  • 24
0

This works, and the navbar collapses at 992px with the css code below:

@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;
  }
}
Sarhad Salam
  • 428
  • 3
  • 12
  • thanks man but it doesn't work for me :/ i tried a lot of codes but i can't fixed :/ – kev Dec 28 '15 at 18:25
0

I have tried the following code with bootstrap 3.3.6 and it works.

@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;
}
}

Please check this jsfiddle

avnaveen
  • 562
  • 2
  • 4
  • 10