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>
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.
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.
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.
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).
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With