Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap, keep menu aligned to container width

My question is how can I get the navigation content to align to the page content width and not be 100%. I still want the black nav background to be 100% though. You can achieve this with a navbar-fixed-top, but I don't want my nav fixed. Usually container does this for you, but in this scenario it does not margin auto the content.

I have a nav menu like this.

<div class="navbar">
  <div class="navbar-inner">
    <div class="container">

      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>

            <a class="brand visible-phone visible-tablet" href="#">Brand</a>

            <div class="nav-collapse">
                <ul class="nav">
                  <li class="active"><a href="#">Item 1</a></li>
                  <li><a href="#">Item 2</a></li>
                  <li><a href="#">Item 3</a></li>
                </ul>

            </div>

    </div>
  </div>
</div><!-- END .navbar -->
like image 694
Ian Hoar Avatar asked Jul 14 '12 05:07

Ian Hoar


1 Answers

I figured this out, so if anyone needs to know here is the solution. I have my entire nav wrapped in a #navbar-top id. This is recommended so you don't override Bootstrap globally.

@media (min-width: 1200px) {
    #navbar-top .container {
        width:1170px;
    }   
}
@media (min-width: 979px) and (max-width: 1200px) {
    #navbar-top .container {
        width:960px;
    }   
}
@media (min-width: 768px) and (max-width: 979px) {
    #navbar-top .container {
        width:744px;
    }   
}

This forces the .container to have a width at each resolution even when the navbar is not fixed.

like image 198
Ian Hoar Avatar answered Nov 16 '22 05:11

Ian Hoar