网格内的Bootstrap 3内联导航栏

时间:2015-01-12 12:40:12

标签: html css twitter-bootstrap twitter-bootstrap-3 grid

我制作了简单的bootstrap导航栏,但是如何让它适合网格系统,我想成为col-md-8或其他因为我是这个网格系统的新手,我知道如何制作简单的东西但不是此

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
        <!-- 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>
            <a class="navbar-brand" href="#">Flatie</a>
        </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 navbar-nav navbar-right">
                <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><a href="#">Something else here</a></li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

以下是JsFiddle

3 个答案:

答案 0 :(得分:9)

将它包装在带有类的行的div中,或者甚至更好地将所有代码包装在类容器的div中。如下所示:

<div class="container">
     <div class="row">
      <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
       <div class="container">
        <!-- 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>
            <a class="navbar-brand" href="#">Flatie</a>
        </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 navbar-nav navbar-right">
                <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><a href="#">Something else here</a></li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
  </nav>

</div><!--end of row-->
<div class="row">add other contain</div>

</div><!--end of container-->

答案 1 :(得分:2)

默认情况下,nav元素获取全宽,但是如果要将其包含在网格系统中,则在元素中包含导航元素,该元素具有根据网格系统的类,即col-md-8,col-xs-6等。< / p>

例如

  '<div class="col-md-8"> <nav class="navbar navbar-default navbar-fixed-top" role="navigation">'...

   ... Your nav menu Code

  '</nav></div><div class="col-md-4"></div>'

答案 2 :(得分:1)

好的,我做到了,我把容器连成一排,给了容器一个类col-md-8并居中。 在css id中这是以中心:

.centered {
    margin: 0 auto;
    float: none
}

保证金0自动为中心 float none是因为col-md-8向左浮动。