简体   繁体   中英

Bootstrap Collapsed Menu

I'm having problems with my Bootstrap collapsed navbar, where the items in the menu wont appear on a single line as they should. It may have something to do with my navbar floating right, which I wish to keep as it goes with the design.

Here is the code in question, I have used placeholders for the menu items:

<div id="divNav">
                 <nav class="navbar navbar-default navbar-static-top" role="navigation">
                  <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                      </button>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                      <ul class="nav nav-pills navbar-right">
                        <li class="active"><a href="index.html">Home</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                        <li><a href="something.html">something</a></li>
                      </ul>
                    </div><!-- /.navbar-collapse -->
                  </div><!-- /.container-fluid -->
                </nav>
            </div> <!--End of divNav -->

And here is a photo of the unexpect behavior once collapsed, is there a way round this?

http://imgur.com/fP6WcOt

Thanks

.nav-pills , though their name sort of implies (if you are not familiar with Bootstrap) that they work inside the .navbar , they don't actually go there, that is not their intended use.

If you want a design pattern like .nav-pills in the navbar, you will need to copy (not remove) their styles out of the un-minified bootstrap.css and rename them. Put the float part in a min-width media query and the rest of the styles outside and before the min-width media query.

DEMO: http://jsbin.com/zoham/1/edit

NEW CSS:

.navbar-nav-pills > li > a {
    border-radius: 2px
}
.navbar-nav-pills > li + li {
    margin-left: 2px
}
.navbar-nav-pills > li.active > a,
.navbar-nav-pills > li.active > a:hover,
.navbar-nav-pills > li.active > a:focus {
    color: #ffffff;
    background-color: #428bca;
}
@media (min-width:768px) { 
    .navbar-nav-pills > li {
        float: left
    }
}

HTML - change class name :

<ul class="nav navbar-nav-pills navbar-right">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM