Let's talk about what to do. On a mobile device i want the menu to center the text, default bootstrap aligns the menu items to the left.
This is not what we want. But we know bootstrap, it uses flexbox because it is awesome! So let's start with the default navbar from bootstrap and play a bit with it. This is what we ended up with;
And if you did not, let's explain! From the example i added a container, still default. Next on the navbar-nav
i just added a class align-items-center
. And done! Nav items centered on a mobile screen.
Ok, on the example there was a form on the left. We replaced that with a couple of buttons. But the inner
workings is the same, only that the form is a bit more checking out. But we added a class d-flex flex-row
justify-content-center
on the container. This will still float the container to the right on a
desktop, but flexes the container on a mobile screen. This can be added on the form on the basic example.
Also, on the dropdown elements we added a text-center
class. On the nav-link
and the
dropdown-item
items. This is so that text is also centered
And that's it! We are done, we have a nice centered navbar.
Just to be sure. Let's do that again. Now with a copy paste from the bootstrap page and the classes we mentioned!
Enjoy!