Bootstrap - Navbar不会在移动设备上显示

时间:2016-07-20 23:03:21

标签: html twitter-bootstrap

当我将浏览器窗口尺寸缩小以查看其在移动设备上的外观时,移动设备上用于查看导航栏的按钮不会显示。这是一个CodePen来查看我的代码

<div class="container">
  <div class="navbar navbar-default navbar-fixed-top">
    <div class="container">
      <a class="navbar-brand" href="#"><h4>EmulateOS.tk</h4></a>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
           <li class="active"><a href="#">Home</a></li>
           <li><a href="#">Mac OS9</a></li>
            <li><a href="#">DOS</a></li>
            <li><a href="#">Windows '95</a></li>
          </ul>
            <form class="navbar-form navbar-left" role="search">
              <input type="text" class="form-control" placeholder="Search">
              <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
            </form>
       </div>
     </div>
   </div>
   </div>

2 个答案:

答案 0 :(得分:0)

导航应该在移动屏幕上消失 - 在移动视图中,通过单击按钮激活菜单可以看到菜单。 navbar-collapse类确保了这一点。有关如何实现此目的,请参阅Bootstrap文档:

http://getbootstrap.com/components/#navbar

他们的例子可以实现不同的方式:

http://getbootstrap.com/getting-started/#examples

具体来说,这是代码的关键方面:

<div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <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="#">Brand</a>
    </div>

答案 1 :(得分:0)

您的代码缺少一些启动带样式。这是工作代码 -

http://codepen.io/anon/pen/BzAWVa

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap Course</title>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <style type="text/css">
        body {
            padding: 60px;
        }
    </style>
</head>

<body>
    <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">

            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#navbar" aria-expanded="false" aria-controls="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="#">EmulateOS.tk</a>
            </div>

            <div id="navbar" class="navbar-collapse collapse">

                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">Mac OS9</a></li>
                    <li><a href="#">DOS</a></li>
                    <li><a href="#">Windows '95</a></li>
                </ul>
                <form class="navbar-form navbar-left" role="search">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
                </form>


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

    </nav>

    <div class="container">

        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Panel title</h3>
            </div>
            <div class="panel-body">
                Panel content
            </div>
        </div>

        <a data-target="#myModal" role="button" class="btn btn-warning" data-toggle="modal"><span class="glyphicon glyphicon-hand-up"></span>Sign up for weekly newsletter</a>

        <div class="modal fade" id="myModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Sign up for the newsletter</h4>
                        <div class=modal-body>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <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>

</body>

</html>