下拉子菜单未正确对齐。它走到了顶端

时间:2017-02-22 03:08:14

标签: html css twitter-bootstrap drop-down-menu

当我进入手机屏幕时,我的导航栏子菜单就像这样 my navbar submenu goes like this when i go to mobile screen

当我使用手机屏幕时,这就是我想要在我的导航栏子菜单中发生的事情。

this is what i want to be happen to my navbar submenu when i use mobile screen.

这是我使用的代码。有人试图向我解释

c()
.navbar-toggle {
  z-index:3;
}

.navbar-nav {
    float:none;
    display: block;
    text-align: center;
}

.navbar-nav > li {
    display: inline-block;
    float:none;
}

1 个答案:

答案 0 :(得分:0)

你可以这样做 -

工作示例



<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
           <style type="text/css">
          
  #dropdown-menu {
position: absolute;
background-color: white;
border: 2px;
}

.navbar-nav {
    float:none;
    display: block;
    text-align: center;
}

.navbar-nav > li {
    display: inline-block;
    float:left;
}
           </style>
           
           </head>
           <body>
           <div class="container-fluid">
    <nav class="navbar navbar-default" role="navigation">
    <!-- Brand and toggle get grouped for better mobile display -->
    
    <!-- Collect the nav links, forms, and other content for toggling -->
    
      <ul class="nav navbar-nav">
      <div class="row">
<div class="col-xs-2">
        <li><a href="#">Home</a></li>
        </div>
        <div class="col-xs-2">
        <li><a href="#">Sauce</a></li>
        </div>
        <div class="col-xs-2">
        <li  class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Syrup <b class="caret"></b></a>
          <ul id="dropdown-menu" 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><a href="#">Separated link</a></li>
          </ul>
        </li>
        </div>
        <div class="col-xs-2">
        <li style="float: right;"><a href="#">Frappe</a></li>
        </div>
        <div class="col-xs-2">
        <li style="float: right;"><a href="#">Accessories</a></li>
        </div>
        <div class="col-xs-2">
        <li style="float: right;"><a href="#">Contact</a></li>
        </div>
        </div>
      </ul>

   <!-- /.navbar-collapse -->
</nav>
</div>

           </body>
           </html>
           
&#13;
&#13;
&#13;

希望这有帮助!