1
votes

im trying to center my navbar with no luck at all.. Anyone here knows how to center it?

Here's my code:

            <nav class=" navbar navbar-default" role="navigation">
                <ul class="nav navbar-nav">
                    <li><a href="#">HEM</a></li>
                    <li><a href="#">OM</a></li>
                    <li><a href="#">VAD ÄR VI?</a></li>
                    <li><a href="#">TJÄNSTER</a></li>
                    <li><a href="#">VARFÖR?</a></li>
                    <li><a href="#">KONTAKT</a></li>
                </ul>

I cant find the rows in bootstrap.css, but if you really need the code from the css doc, i try to find it.

5
<nav> is a full width element? If it is, try using a fixed width on the <ul> and add to it a margin:0 auto;Patrick

5 Answers

2
votes

This one works :- DEMO

<div class="text-center">
     <nav class=" navbar navbar-default" role="navigation">
                <ul class="nav navbar-nav">
                    <li><a href="#">HEM</a></li>
                    <li><a href="#">OM</a></li>
                    <li><a href="#">VAD ÄR VI?</a></li>
                    <li><a href="#">TJÄNSTER</a></li>
                    <li><a href="#">VARFÖR?</a></li>
                    <li><a href="#">KONTAKT</a></li>
                </ul>
       </nav>
</div>

CSS

.navbar .nav, .navbar .nav > li {
    float:none;
    display:inline-block;    
}
1
votes

Try to add css .navbar-nav li {display:inline-block;} <-- this let all <li> tags lined up.

Check this FIDDLE to view more details.

Let me know if this was what you're looking for :)

1
votes

Updated 2017

In Bootstrap 3.x, you can use the nav-justified class... No custom CSS required:

 <nav class="navbar navbar-default" role="navigation">
   <div class="container">
     <ul class="nav nav-justified">
       <li><a href="#">HEM</a></li>
       <li><a href="#">OM</a></li>
       <li><a href="#">VAD ÄR VI?</a></li>
       <li><a href="#">TJÄNSTER</a></li>
       <li><a href="#">VARFÖR?</a></li>
       <li><a href="#">KONTAKT</a></li>
     </ul>
   </div>
</nav>

https://www.bootply.com/109568

Bootstrap 4 there is the nav-fill class...

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
    <div class="container">
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbar10">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse" id="navbar10">
            <ul class="navbar-nav nav-fill w-100">
                <li class="nav-item">
                    <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Link</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

https://www.bootply.com/bjgAw3F3Ps

0
votes

FIDDLE

just a little fix to what @Fiskolin has done, if you want it to always be centered you should make sure that the UL will center all text by adding this to it.

ul { text-align:center; }
0
votes

I am using this for Bootstrap v3.

@media (min-width: 768px) {
    .navbar ul {
        float: unset !important;
        justify-content: center;
        display: flex;
    }
}