Bootstrap: center some navbar items

后端 未结 4 2041
情歌与酒
情歌与酒 2020-12-09 20:15

I would like to have a bootstrap navbar where some nav items are left-justified, some are right justified, and some are centered in the remaining space between them.

相关标签:
4条回答
  • 2020-12-09 20:51

    use this css actually in bootstrap li and ul are float left http://jsfiddle.net/b7whs/4/

    @import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
    
    .container {
        margin-top: 10px;
    }
    
    .nav.nav-center {
        display: inline-block;
        left: 0;
        right: 0;
        text-align:center;width:70%;
    }
    .nav.nav-center li,.nav.nav-center li  a{display:inline;float:none;line-height:40px;}
    
    0 讨论(0)
  • 2020-12-09 21:05

    Just found out the solution myself today.

    Just Add the CSS as:

    /* center the navbar*/
    .center.navbar .nav,
    .center.navbar .nav > li {
        float:none;
        display:inline-block;
        *display:inline; /* ie7 fix */
        *zoom:1; /* hasLayout ie7 trigger */
        vertical-align: top;
    }
    
    .center .navbar-inner {
        text-align:center;
    }
    
    .center .dropdown-menu {
        text-align: left;
    }
    

    and add center class to navbar like this

    <div class="navbar navbar-inverse navbar-fixed-top center">
      <div class="navbar-inner">
        <div class="container center">
          ----
        </div>
      </div>
    </div>
    
    0 讨论(0)
  • 2020-12-09 21:07

    You just needed a couple of styles to get the behaviour that I think you wanted. It looks like you were going the display:inline-block route to center the elements, so I'll just continue along that approach. To your existing styles, add/modify definitions so that these styles are included:

    .nav.nav-center {
        margin:0;
        float:none;
    }
    
    .navbar-inner{
        text-align:center;
    }
    

    With that, the two options should move to the exact center of your navigation bar. Here's a JSFiddle example to show you what this would look like. I hope this is what you were looking for! If not, let me know and I'll be happy to help further.

    0 讨论(0)
  • 2020-12-09 21:07

    add this code

    <div class="col-lg-4 col-lg-offset-5 col-xs-2 col-xs-offset-4"> <ul class=" nav navbar-nav "> <li><a href="#">products</a></li> </ul> </div>

    0 讨论(0)
提交回复
热议问题