0

The default fixed-top navbar in Bootstrap spans the full width of the viewport. I want it to display contain it within a container div. I am able to contain the left side using the following CSS override:

.navbar-fixed-top,
.navbar-fixed-bottom {
    position: fixed;
    width:100%;
    right: auto;
    left: auto;
    z-index: 1030;
}

But the navbar still extends to full window on the right.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • can you put this into a codepen or jsfiddle? It'll make it easier for you to understand the answer... and easier for people to find the answer. – Todd Dec 11 '14 at 03:31
  • try the answer mentioned here...http://stackoverflow.com/questions/4962266/css-positionfixed-inside-a-positioned-element - without the use of left and right values and do adjustments using margin values. – Praveen Puglia Dec 11 '14 at 09:04

2 Answers2

0

make sure everything is well nested in bootstrap

 <body>
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <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>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container">

      <div class="starter-template">
        <h1>Bootstrap starter template</h1>
        <p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
      </div>

    </div><!-- /.container -->

Suresh Karia
  • 17,550
  • 18
  • 67
  • 85
0

Just take the colors out of the navbar element in your own stylesheet and add the desired color to the interior container within the navbar.

.navbar {
    background-color: transparent;
    background: transparent;
    border:none;
}
.navbar .container { 
    background-color: black;
    background: blue;
    border:grey;
}

LINK: http://www.bootply.com/Yg3uxVtxhu

Opaw Nako
  • 1,096
  • 1
  • 8
  • 17