17

I'm putting together a rough navbar using Twitter bootstrap.

TopNav1

There's a breakpoint at which the width of the device will cause the navbar items to collapse and show a menu button instead:

TopNav3

How can I change the breakpoint so the navbar collapses sooner? At the moment its able to break on to a new line when it comes up against the logo, which doesn't look too great:

TopNav2

I've tried a fix detailed here, but it seemed to break the collapsed menu (couldn't expand it again afterwards).

Here's the html:

    <!-- navigation -->
    <div class="navbar navbar-default navbar-static-top">
        <div class="container-fluid">
            <div class="navbar-header">

                <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a class="navbar-brand" href="#"><img class="ManeEventLogo" src="/img/ManeEventLogoWhite-Sm.png"></a>
            </div>

            <div class="collapse navbar-collapse navbar-responsive-collapse">

                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/index.php">HOME</a>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">SERVICES <span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="/services/cutting-styling/index.php">Cutting & Styling</a></li>
                                <li><a href="/services/coloring/index.php">Coloring</a></li>                                
                                <li><a href="/services/hair-straightening-relaxing/index.php">Permanent Hair Straightening & Relaxing</a></li>
                                <li><a href="/services/balmain-hair-extensions/index.php">Balmain Hair Extensions</a></li>
                            </ul>
                    <li>
                        <a href="/wedding-day/index.php">WEDDING DAY</a>
                    </li>
                    <li>
                        <a href="/expertise-team/index.php">THE EXPERTISE TEAM</a>
                    </li>
                    <li>
                        <a href="/photo-gallery/index.php">PHOTO GALLERY</a>
                    </li>
                    <li>
                        <a href="/blog/index.php">BLOG</a>
                    </li>
                </ul>

            </div>
        </div>
    </div>
Matt Hall
  • 2,412
  • 7
  • 38
  • 62

2 Answers2

40

Which version of bootstrap are you using? 3.1? Anyway, I need as well your css to help you to fix it, but generally:

@media (max-width: 1200px) {
    .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;
    }
   .navbar-nav .open .dropdown-menu {
       position: static;
       float: none;
       width: auto;
       margin-top: 0;
       background-color: transparent;
       border: 0;
       -webkit-box-shadow: none;
       box-shadow: none;
    }
}

The max width is the breakpoint. Copied from Bootply (with demo included there).

Karolína Vyskočilová
  • 1,305
  • 1
  • 18
  • 29
  • 1
    That's mostly worked.. thank you. There's an issue with the "Services" item, which has a drop-down menu attached to it. When the navbar is collapsed and then expanded through the menu button, the "Services" drop-down expands in the same way it did prior to the navbar being collapsed. – Matt Hall Feb 22 '15 at 16:04
  • I'm sorry, but I'm lost, could you give me a link or printscreen? I don't know, what do you exactly want to, but you can change behavior of it the same way, just put your css into `@media (max-width: 1200px) {}` and that's all – Karolína Vyskočilová Feb 22 '15 at 16:09
  • 1
    http://jsfiddle.net/7jLm8btr/ Resize the browser width until the navbar collapses to the menu button, then try to open the "Services" drop-down. Notice the drop-down menu is floating on top of everything.. normal behaviour would be for it to expand under the "Services" item. – Matt Hall Feb 22 '15 at 16:17
  • @MattHall It looks fine to me - dropdown is opened below "Sevices" content, see prinscreen [link](https://www.uploady.com/download/pfP44GxpOCD/jIesiEZxjm37j5J5) – Karolína Vyskočilová Feb 22 '15 at 16:38
  • Weird.. it's not working properly on my local version: [link](https://www.uploady.com/#!/download/OHX0bE0cYGF/zLmIqbcUAIeTsfqO) – Matt Hall Feb 22 '15 at 16:48
  • @MattHall try to explore using inspector what is applied to your sub menu, there has to be something making the mess. – Karolína Vyskočilová Feb 22 '15 at 17:11
  • ahh.. it seems to do it in the fiddle when you actually trigger the break-point. So if the navbar is already collapsed it won't do it.. try expanding and collapsing the navbar by resizing your browser, then you should see what I'm seeing. – Matt Hall Feb 22 '15 at 17:12
  • 2
    @MattHall Here you go, I've edited my answer, code for _.navbar-nav .open .dropdown-menu_ need to be included as well. You can probably mark it as correct answer. ;) – Karolína Vyskočilová Feb 22 '15 at 17:28
  • @kybernaut-cz that's done the trick! thank you :) – Matt Hall Feb 22 '15 at 20:57
  • there seems to be a problem with overflow – don_Bigote Dec 07 '16 at 05:25
  • @don_Bigote where? Could you send me a bootply link where I can see it? Are you sure, that you didn't mixed it with bootply rendering issue (you need to click for smaller wides) – Karolína Vyskočilová Dec 09 '16 at 07:49
  • @kybernaut.cz I am sure that the problem is with your code and not bootply. I tried it on my local machine. The problem is that if you add more `
  • ` tags then you can't scroll to view the content in the `
  • ` tags. You need to add this to make it work: `.navbar-nav { max-height: 300px; overflow-y: scroll!important; }`
  • – don_Bigote Dec 11 '16 at 19:10
  • Awesome @@kybernaut.cz! Works like a charm! – yardpenalty.com May 14 '17 at 14:41
  • I had some issues with the menu going open and closes again directly after. Fixed this by adding: .navbar-collapse.collapse.in: display: block!important; – Nrzonline Jul 09 '17 at 20:56