Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap: How to make top fixed navbar stay in container and not stretch?

I'm working with Twitter Bootstrap and the regular navbar you see in the guides: http://twitter.github.io/bootstrap/components.html#navbar

I don't want the navigation to stretch all the way left or right but stay where I can see both sides just like in the guide. The only difference is it would be fixed to the top.

I was wondering, how do I make this become a fixed navbar as if I was using the navbar-fixed-top class?

like image 325
Jryl Avatar asked Jun 25 '13 21:06

Jryl


People also ask

How do I stop bootstrap navbar from collapsing?

For navbars that never collapse, add the . navbar-expand class on the navbar. For navbars that always collapse, don't add any .

How do I make navbar stay on top in bootstrap 4?

Use the . sticky-top class to make the navbar fixed/stay at the top of the page when you scroll past it.

How do I keep the navbar always on top?

I found it necessary to add a z-index with a high enough number for the navbar to appear always on top of other elements.


2 Answers

You should be able to do:

<div class="navbar-fixed-top container">
  <div class="navbar">
    <div class="navbar-inner">
      <a class="brand" href="#">Title</a>
      <ul class="nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
      </ul>
    </div>
  </div>
</div>
like image 94
JasonM Avatar answered Oct 09 '22 21:10

JasonM


Bootstrap 4, use .container inside nav:

Demo

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
	<div class="container">
		<a class="navbar-brand site-title" href="#">Hello World</a>
		<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHelloWorld" aria-controls="navbarHelloWorld" aria-expanded="false" aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>
		<div class="collapse navbar-collapse" id="navbarHelloWorld">
			<ul id="menu-top-menu" class="navbar-nav mr-auto">
				<li class="nav-item"><a href="#" class="nav-link">About</a></li>
				<li class="nav-item"><a href="#" class="nav-link">Blog</a></li>
				<li class="nav-item"><a href="#" class="nav-link">Contact</a></li>
			</ul>
			<form class="form-inline my-2 my-lg-0">
				<input class="form-control mr-sm-2" placeholder="Search" type="text">
				<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
			</form>
		</div>
	</div>
</nav>
like image 39
Nabil Kadimi Avatar answered Oct 09 '22 20:10

Nabil Kadimi