2016-02-16 56 views
0

我最近一直在探索bootstrap,我正在努力使用我的导航栏。下面的代码显示了我希望它看起来如何,当我像手机一样调整浏览器窗口时出现问题。当我点击热狗按钮时,它只显示我添加用户名和密码的选项,但我也想访问这些链接。为了让我获得我正在寻找的布局,我使用了两个导航栏。我认为这是我的问题。我怎样才能达到相同的布局,但只有一个导航栏?我想在窗口很小的时候看到所有的链接和密码框,我也试图摆脱显示有两个导航栏的黑色线条。带引导程序的导航栏布局

<html> 

    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
    <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> 
    <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" 
    rel="stylesheet" type="text/css"> 
    <link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" 
    rel="stylesheet" type="text/css"> 
    </head> 

    <body> 
    <div class="navbar navbar-default navbar-static-top"> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
     <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> 
     <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" 
     rel="stylesheet" type="text/css"> 
     <link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" 
     rel="stylesheet" type="text/css"> 
     <div class="navbar navbar-default navbar-inverse navbar-static-top"> 
     <div class="navbar navbar-default navbar-inverse navbar-static-top"> 
      <div class="container"> 
      <div class="navbar-header"> 
       <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main"> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       </button> 
       <a class="navbar-brand" href="#">&nbsp; &nbsp; Website Name</a> 
      </div> 
      <center> 
       <div class="navbar-collapse collapse" id="navbar-main"> 
       <form class="navbar-form navbar-right" role="search"> 
        <div class="form-group"> 
        <input type="text" class="form-control" name="username" placeholder="Username"> 
        </div> 
        <div class="form-group"> 
        <input type="text" class="form-control" name="password" placeholder="Password"> 
        </div> 
        <button type="submit" class="btn btn-default">Sign In</button> 
       </form> 
       </div> 
      </center> 
      </div> 
     </div> 
     <div class="navbar navbar-default navbar-inverse navbar-static-top"> 
      <div class="container"> 
      <div class="navbar-header"> 
       <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main"> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       </button> 
       <!--<a class="navbar-brand" href="#">MatchedManager</a>--> 
      </div> 
      <center> 
       <div class="navbar-collapse collapse" id="navbar-main"> 
       <ul class="nav navbar-left navbar-nav"> 
        <li> 
        <a href="#">Home</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> 
         <li class="divider"></li> 
         <li> 
         <a href="#">One more separated link</a> 
         </li> 
        </ul> 
        </li> 
        <li> 
        <a href="#">Link</a> 
        </li> 
        <li> 
        <a href="#">Link</a> 
        </li> 
        <li> 
        <a href="#">Link</a> 
        </li> 
       </ul> 
       <ul class="nav navbar-nav navbar-right"> 
        <li> 
        <a href="#">Register</a> 
        </li> 
        <li> 
        <a href="#">Forgot Login</a> 
        </li> 
       </ul> 
       </div> 
      </center> 
      </div> 
     </div> 
     </div> 
    </div> 
    </body> 

</html> 
+1

请新增的jsfiddle或codepen演示。否则很难看到你在问什么 – Fergus

+0

请在http://codepen.io/karl001/full/xZBjKj找到。如果你调整窗口的大小,你应该看到我的意思是当屏幕变成手机的大小时屏幕。 – josh

回答

0

这里是你如何能做到这一个navbar一个例子。您只需为链接创建另一个div并相应地定位它们。没有别的。

查看完整页面上的工作示例代码段。

@media (min-width: 768px) { 
 
    .navbar .lower-nav { 
 
    padding-top: 50px; 
 
    margin-left: -15px; 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 
 
<nav class="navbar navbar-inverse navbar-static-top" role="navigation"> 
 
    <div class="container"> 
 
    <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar"> <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="#"> Website Name</a> 
 
    </div> 
 
    <div class="collapse navbar-collapse" id="navbar"> 
 
     <form class="navbar-form navbar-right" role="search"> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" name="username" placeholder="Username"> 
 
     </div> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" name="password" placeholder="Password"> 
 
     </div> 
 
     <button type="submit" class="btn btn-default">Sign In</button> 
 
     </form> 
 
     <div class="lower-nav"> 
 
     <ul class="nav navbar-nav navbar-left"> 
 
      <li><a href="#">Home</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> 
 
       <li class="divider"></li> 
 
       <li><a href="#">One more separated link</a> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
      <li><a href="#">Link</a> 
 
      </li> 
 
      <li><a href="#">Link</a> 
 
      </li> 
 
      <li><a href="#">Link</a> 
 
      </li> 
 
     </ul> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li><a href="#">Register</a> 
 
      </li> 
 
      <li><a href="#">Forgot Login</a> 
 
      </li> 
 
     </ul> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</nav> 
 
<div class="container"> 
 
    <p> 
 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has 
 
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing 
 
    software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a 
 
    galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets 
 
    containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's 
 
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the 
 
    printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, 
 
    but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker 
 
    including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled 
 
    it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
 
    and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since 
 
    the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in 
 
    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting 
 
    industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic 
 
    typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem 
 
    Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer 
 
    took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 
 
    sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's 
 
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
    </p> 
 
</div>

+0

这正是我正在寻找的。我怎样才能得到完整的代码? – josh

+0

这是完整的代码。 – vanburen

+0

非常感谢:) – josh

0

这样的事情呢?该模式允许您添加更多选项,例如“注册”或“忘记密码”,而不必在nav本身需要它们。此外,在移动设备上,它不会显示两个导航栏,而是会正常崩溃。

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
    <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> 
 
    <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> 
 
    <link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet" type="text/css"> 
 
</head> 
 

 
<body> 
 
    <nav class="navbar navbar-inverse"> 
 
    <div class="container-fluid"> 
 
     <div class="navbar-header"> 
 
     <a class="navbar-brand" href="#">WebSiteName</a> 
 
     </div> 
 
     <ul class="nav navbar-nav"> 
 
     <li class="active"><a href="#">Home</a></li> 
 
     <li><a href="#">Page 1</a></li> 
 
     <li><a href="#">Page 2</a></li> 
 
     <li><a href="#">Page 3</a></li> 
 
     </ul> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
     <li><a data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> 
 
     </ul> 
 
    </div> 
 
    </nav> 
 
    <div id="myModal" class="modal fade" role="dialog"> 
 
    <div class="modal-dialog"> 
 

 
     <!-- Modal content--> 
 
     <div class="modal-content"> 
 
     <div class="modal-header"> 
 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
      <h4 class="modal-title">Login</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
      <form> 
 
      <div class="form-group"> 
 
       <input type="text" class="form-control" name="username" placeholder="Username"> 
 
      </div> 
 
      <div class="form-group"> 
 
       <input type="password" class="form-control" name="password" placeholder="Password"> 
 
      </div> 
 

 

 
     </div> 
 
     <div class="modal-footer"> 
 
      <button type="submit" class="btn btn-default" data-dismiss="modal">Sign In</button> 
 
     </div> 
 
     </div> 
 
     </form> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

codepen.io/zanderl/pen/mVoLdY