When working with Bootstrap's Navbar, only use the supported content. Follow the guidance from the docs...
Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl|-xxl} for responsive collapsing and color scheme classes.
Navbars and their contents are fluid by default. Change the container to limit their horizontal width in different ways.
Use our spacing and flex utility classes for controlling spacing and alignment within navbars.
So, following this guidance for your Navbar...
- Assuming you want it to always remain horizontal, add the
navbar-expand
class.
- The
nav-link
s should be contained inside a navbar-nav
(supported content)
- Use the spacing/flex utility classes. To center the
navbar-nav
, use w-100
to create 3 equal width navbar divs/sections. Then justify-content-center
on the navbar-nav
to center content of the middle section.
<nav class="navbar navbar-expand bg-primary mt-3">
<div class="container-fluid">
<div class="w-100">
<img src="//placehold.it/60x30" class="ms-4" width="60" alt="Logo">
<a class="navbar-bran text-light ms-5 fw-bold">TEST</a>
</div>
<div class="navbar-nav justify-content-center">
<a class="nav-link text-light">One</a>
<a class="nav-link text-light">Two</a>
<a class="nav-link text-light">Three</a>
<a class="nav-link text-light">Four</a>
</div>
<div class="w-100">
</div>
</div>
</nav>
Demo
Since Bootstrap 5 still uses flexbox like Bootstrap 4, aligning Navbar content hasn't changed between the 2 versions.