Bootstrap - 使用两个导航栏

时间:2015-03-10 19:54:45

标签: html css twitter-bootstrap

我正在使用twitter bootstrap 3,我试图在同一页面中使用两个导航栏。

以下是我当前实施的一个小提琴:http://jsfiddle.net/SSJVegito/30x80qq8/1/

CSS:

.navbar-position {
position: relative;}

HTML:

  <div class="container">
    <div class="navbar navbar-inverse navbar-fixed-top navbar-position" role="navigation">
        <div class="navbar-header">
            <div class="navbar-header"><a class="navbar-brand" href="#">Brand</a>
            </div>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>

            </button>
        </div>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav pull-right">
                <li><a href="#">Link</a>
                </li>
                <li><a href="#">Link</a>
                </li>
                <li><a href="#">Link</a>
                </li>
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">One more separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="navbar navbar-inverse navbar-static-top" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>

            </button>
        </div>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Link</a>
                </li>
                <li><a href="#">Link</a>
                </li>
                <li><a href="#">Link</a>
                </li>
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">One more separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <button type="button" class="btn btn-default navbar-btn">Button</button>
            <div class="col-sm-3 col-md-3 pull-right">
                <div class="navbar-text">Text</div>
                <form class="navbar-form" role="search">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
                        <div class="input-group-btn">
                            <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

我遇到的问题是我想使用小提琴中的相对定位,但是当我尝试这个时,它会在两个导航栏之间添加一个间距,这是我不想要的。我希望他们一个接一个。我搜索了很多,但我找不到答案。我发现最接近的是一个解决方案,其中两个导航栏以div分隔。

谢谢!

2 个答案:

答案 0 :(得分:2)

Bootstrap导航栏默认具有底部边距,因此只需将以下内容添加到css中即可删除空格:

.navbar {
    margin: 0px;
}

答案 1 :(得分:0)

我刚刚将以下内容添加到CSS

.navbar{
    margin-top:0;
    margin-bottom:0;
}

<强> DEMO