Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap navbar justify / span menu items occupying full width

I use the default Twitter Bootstrap responsive navbar (without the logo and search), but I want the menu items to be spanned, occupying the full width of the menu bar.

Here is what I have now default Bootstrap navbar (see --- as spaces):

[home | menu item 1 | menu item 2 | menu item 3 | contact------------------------] 

and the result I like to have (menu items occupying the full width):

[--home-- | ---menu item 1--- | ---menu item 2--- | ---menu item 3--- | -contact-] 

I hope someone can help.

like image 925
user2024774 Avatar asked Jan 30 '13 10:01

user2024774


People also ask

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

Approach 1: 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%.

How can I make my navbar cover 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 change the spacing between navbar items?

As of Bootstrap 4, you can use the spacing utilities. Add for instance px-2 in the classes of the nav-item to increase the padding.

How can I make my navbar width 100%?

So if you want full-width you either have to wrap your navbar in a row (inside your container) or you just don't use container 's at all. Show activity on this post.


2 Answers

Have a look at Bootstrap's official example:

/* Customize the navbar links to be fill the entire space of the .navbar */ .navbar .navbar-inner {     padding: 0; }  .navbar .nav {     margin: 0;     display: table;     width: 100%; }  .navbar .nav li {     display: table-cell;     width: 1%;     float: none; }  .navbar .nav li a {     font-weight: bold;     text-align: center;     border-left: 1px solid rgba(255, 255, 255, .75);     border-right: 1px solid rgba(0, 0, 0, .1); }  .navbar .nav li:first-child a {     border-left: 0;     border-radius: 3px 0 0 3px; }  .navbar .nav li:last-child a {     border-right: 0;     border-radius: 0 3px 3px 0; } 
like image 165
sgrodzicki Avatar answered Oct 05 '22 20:10

sgrodzicki


The official example works perfectly until you want to use those menu items with the native drop down calls. The drop down becomes the width of all of your drop down items combined.

*note the ">", it will make the style stop from bleeding over into the .dropdown-menu subset.

/* Customize the navbar links to be fill the entire space of the .navbar */  .navbar .navbar-inner {     padding: 0; }  .navbar .nav {     margin: 0;     display: table;     width: 100%; }  .navbar .nav > li {     display: table-cell;     width: 1%;     float: none;     text-align: center; }   .navbar .nav li:first-child a {     border-left: 0;     border-radius: 3px 0 0 3px; }  .navbar .nav li:last-child a {     border-right: 0;     border-radius: 0 3px 3px 0; } 
like image 23
Seif Thompson-Doss Avatar answered Oct 05 '22 22:10

Seif Thompson-Doss