Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4: How to have a full width navbar with the content in a container (Like the SO Navbar)?

I am using Bootstrap 4.

How do I make a navbar like the SO navbar?

With the content aligned like a "container" but the width of a "container-fluid" in bootstrap 4?

I want the width of the "fixed-top" navbar setting without it being fixed-top and the navbar content in a "container".

I would provide an example but I'm trying to make something exactly like the navbar at the top of this page.

like image 805
bbennett36 Avatar asked Jan 12 '17 20:01

bbennett36


People also ask

How do I make the navigation bar full width in Bootstrap?

In Bootstrap 4, full width dropdown in Navbar might be possible by adding CSS properties either internally or externally based on conveniences. Focus on class dropdown and dropdown-menu only. Now, make top margin of dropdown-menu as zero pixel and add width to 100%. We can also use CSS properties through inline method.

How can I make my navbar full width?

The simplest way to get the effect you are looking for (for any number of buttons) is to use a table with a 100% width. A more complicated way is to give each button an equal percentage width such that with the number of buttons it adds up to 100%. You have 5 buttons, so you can put width:20%; on #nav ul li .

How do I align navbar content to the right in Bootstrap 4?

ml-auto class of Bootstrap 4 to align navbar items to the right. The . ml-auto class automatically gives a left margin and shifts navbar items to the right.


3 Answers

I was able to get the menu to 100% width

<ul class="navbar-nav nav-fill w-100">
  <li class="nav-item">
    <a href="#" class="nav-link">Home</a>
  </li>
  <li class="nav-item">
    <a href="#" class="nav-link">Contact</a>
  </li>
  <li class="nav-item">
    <a href="#" class="nav-link">About</a>
  </li>
</ul>

using nav-fill w-100 with Bootstrap 4

like image 59
Ravi Ram Avatar answered Oct 10 '22 23:10

Ravi Ram


Wrap an element around the .container element.

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' );

#primary-nav {
  background-color: skyblue;
}
<div id="primary-nav">

  <div class="container">
  
    <ul class="nav">
      <li class="nav-item">
        <a href="#" class="nav-link">Home</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Contact</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">About</a>
      </li>
    </ul>    
    
  </div>
  
</div>
like image 34
hungerstar Avatar answered Oct 11 '22 00:10

hungerstar


I had met this issue also. I solved by put the <nav>...</nav> outside the <div class='container'>...</div> or <div class='container-fluid'>...</div>.

like image 13
Vandy Sodanheang Avatar answered Oct 10 '22 22:10

Vandy Sodanheang