Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I center a Navbar in react-bootstrap

I am hoping that this is a simple question, and I see that some folks have asked a similar question about bootstrap. I haven't been able to work one of those answers into a solution that works for me, and I think there may be a simpler react-bootstrap answer in any case.

Code example is here: https://codesandbox.io/s/yq5jvl9lz9

Here's what it looks like, when the viewport is wide enough: Navbar as produced by my Codesandbox code

Here's more-or-less what I want: What I'm shooting for

Your help will be greatly appreciated! Thanks, Nat

EDIT 12/22/18: Starting with the information from @Cristian below, I modified the example. I needed display: inline-block in addition to width: 100%. Unfortunately, at larger screen sizes, the "brand" is now mis-aligned with the menu items: misaligned navbar

Any other fixes appreciated! I have posted this as a fresh question, so answers can go there (and points for accepted answer!)

like image 994
Nat Kuhn Avatar asked Nov 30 '17 03:11

Nat Kuhn


People also ask

How do I center navbar items in React Bootstrap?

The solution to your problem would be styling the navbar-brand or any other element by using text-align: center however, this will not work unless you also specify width: 100% .

How do I center a navbar element?

You can move the nav elements to the center by putting text-align:center on the ul because the list elements have been set to inline-block which means they can be centred in the same way that you can centre text.

How do I center text in navbar Bootstrap?

By default, navs are left-aligned, but you can easily change them to center or right aligned. Centered with . justify-content-center : Active.


2 Answers

I think className='m-auto' at Nav is enough

like image 163
Leo Avatar answered Jan 04 '23 06:01

Leo


I had the same question, and this worked for me:

Add className="justify-content-center" to the parent.

Example:

<Navbar className="justify-content-center">
    <Navbar.Brand/>
</Navbar>
like image 29
Dan-Alexandru Jecu Avatar answered Jan 04 '23 05:01

Dan-Alexandru Jecu