Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Navbar Center Text

I have recently implemented a collapse bootstrap navbar to my website. However I have an issue with it when it is in its full form. The text is aligned to the left of the navbar and despite much CSS config, and browsing of stackoverflow none of the changes I have tried have been successful at all. I am trying to change the navbar so that the text/links within it are centralized.

        <div class="navbar-header">
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">

                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>


        </div><!-- end navbar-header -->

        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#home">Home</a>
                    <li><a href="#home">Days Out</a></li>
                    <li><a href="#home">Ghosts</a></li>
                    <li><a href="#home">Beasts</a></li>
                    <li><a href="#home">History</a></li>
                    <li><a href="#home">About Us</a></li>
                    <li><a href="#home">Gifts</a></li>
                    <li><a href="#home">Blog</a></li>
                    <li><a href="#home">Contact Us</a></li>
                </ul>
            </div><!-- end collapse -->
        </div>
like image 865
Adam Fenwick Avatar asked Jan 26 '15 12:01

Adam Fenwick


People also ask

How do I Center Center a navbar in Bootstrap?

The menu will be placed in three different positions, left, right, and center. Add the custom defined class named navbar-center to align menu center. CSS Code. The following CSS code of the navbar-center class will align the menu or text content to the center position in Bootstrap navbar.

How to create a navbar with bootstrap?

The Bootstrap libraries need to be included first to create navigation bar with Bootstrap. The following HTML creates a navbar with Bootstrap. The menu will be placed in three different positions, left, right, and center. Add the custom defined class named navbar-center to align menu center.

How to align menu links in Bootstrap navbar?

Generally, the menu is aligned to the left or right side of the top navigation bar. Bootstrap provides an easy way to control the menu alignment. To align the text or menu links in Bootstrap navbar, navbar-nav and navbar-left or navbar-right are used. However, sometimes it requires aligning menu links in the center of the navbar.

How to extend or collapse a navigation bar in Bootstrap?

With Bootstrap, a navigation bar can extend or collapse, depending on the screen size. A standard navigation bar is created with the.navbar class, followed by a responsive collapsing class:.navbar-expand-xxl|xl|lg|md|sm (stacks the navbar vertically on xxlarge, extra large, large, medium or small screens).


1 Answers

You just need to change the float behavior of the navbar, try adding this styles:

.navbar-collapse {
  text-align:center;
}
.navbar-nav {
    display:inline-block;
    float:none;
}

BootplyDemo

like image 169
DaniP Avatar answered Oct 10 '22 22:10

DaniP