如何将两个navbar-collapse内容放在同一行中

时间:2014-07-06 09:43:28

标签: jquery html css twitter-bootstrap-3

我必须使用navbar-collapse内容。我只想在同一行(内联)中显示这些内容。

<header class="navbar navbar-fixed-top" role="navigation">
<div class="navbar-inner">
    <div class="container">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-rt-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-mid-collapse">
            <span class="glyphicon glyphicon-search"></span>
        </button>
        <a class="navbar-brand" rel="home" href="">My Project</a>
        <div class="collapse navbar-collapse" id="navbar-mid-collapse">
                <form class="navbar-form form-inline" role="search" method="get" id="search-form" name="search-form">
                    <div class="input-group">
                        <input type="text" class="form-control">

                        <div class="input-group-btn">
                            <button type="submit" class="btn btn-success"><span
                                    class="glyphicon glyphicon-search"></span></button>
                        </div>
                    </div>
                </form>
        </div>
        <div class="collapse navbar-collapse" id="navbar-rt-collapse">
            <ul class="nav navbar-nav">
                <li><a data-toggle="modal" href="#" data-target="#">Login</a></li>
                <li><a data-toggle="modal" href="#" data-target="#">Register</a></li>
            </ul>
        </div>
    </div>
</div>

Output

那么,如何在同一行显示#nabar-mid-collapse和#navbar-rt-collapse? 感谢

3 个答案:

答案 0 :(得分:2)

您需要额外的一点css并对您的标记进行调整才能获得所需的结果:

<强> CSS:

body {
    padding-top: 50px;
}
.navbar-inverse .navbar-toggle {
    color: #fff;
    width: 44px;
    height: 36px;
}
@media (max-width: 767px) {
    .navbar-inverse .navbar-collapse .navbar-form{
        margin: 0;
        border: 0 none;
    }
    .navbar-form .form-group {
        float: left;
        min-width: 80%;
        margin-right: 10px;
    }
}
@media (min-width: 768px) {
    .navbar-collapse.collapse {
        display: inline-block!important;
        float: left;
    }
}

<强> HTML:

<header class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target="#navbar-rt-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target="#navbar-mid-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="glyphicon glyphicon-search"></span>
            </button>
        <a class="navbar-brand" rel="home" href="">My Project</a>
        </div>
        <div class="navbar-collapse collapse" id="navbar-mid-collapse">
          <form class="navbar-form" role="search">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"></span></button>
          </form>
        </div>
        <div class="navbar-collapse collapse" id="navbar-rt-collapse">
          <ul class="nav navbar-nav">
                <li><a data-toggle="modal" href="#" data-target="#">Login</a></li>
                <li><a data-toggle="modal" href="#" data-target="#">Register</a></li>
          </ul>
        </div>
    </div>
</header>

Bootply Demo

答案 1 :(得分:0)

#nabar-mid-collapse#navbar-rt-collapse包裹在带有row-fluid类的div中,

并将类col-xs-4(*或任何相应的.col类根据每个项目所需的宽度*)应用于它们。

详细了解bootstrap css documentation

的网格系统部分

Demo

答案 2 :(得分:0)

我遇到了这个问题,@ jme11的答案给了我这样做的想法:

//multiple .navbar-collapse.collapse
@media (max-width: 767px) {
    .navbar-collapse:after {
        clear:both;
    }
}
@media (min-width: 768px) {
    .navbar-collapse:after {
        clear:none;
    }
}

希望它可以帮助人们遇到这篇文章。