Bootstrap导航栏在移动(窄屏幕)视图中扩展不正确

时间:2016-03-12 06:55:29

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

我正在关注Bootstrap的视频教程。但是,我的bootstrap导航栏会扩展并显示在网站徽标旁边的移动设备(窄屏幕)中。相关图片:

1 - Narrow screen view with menu expanded

在大多数普通网站上,它应该出现在徽标下面。

2 - Example of a Bootstrap website that has the correctly working mobile menu

这是我的代码

@import url(https://fonts.googleapis.com/css?family=Share+Tech+Mono);

body {
    font-family: 'Share Tech Mono', monospace;
    background-color: #fff;
}

.navbar {
    padding-top: 30px;    
    font-size: 26px;
    font-size-adjust: auto;
    background-color: antiquewhite;
}

.navbar-nav > li {
    padding-left: 15px;
}

.icon-bar {
    background-color: #000;
}

.row {
    padding: 10px;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>My website</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/bootstrap-theme.min.css" rel="stylesheet">
        <link href="css/styles.css" rel="stylesheet">
    </head>
    <body>
        <div class="navbar navbar-static-top">
            <div class="container">
                <a class="navbar-brand" href="">My Logo</a>
                
                <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <div class="collapse navbar-collapse navHeaderCollapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">Blog</a></li>
                        <li><a href="#">Contact</a></li>
                    </ul>
                </div>
            </div>
        </div>
        
        <!-- Main section of homepage -->
        <div class="container-fluid">
            <div class="row"></div> <div class="row"></div> <div class="row"></div>
            <div class="row"></div> <div class="row"></div>
        </div>
        
        <script src="js/jquery-1.12.1.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>

有人可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

你已经忘记了组合品牌和按钮的包装:

<div class="navbar-header">
   <button class="navbar-toggle" data-toggle="collapse" data-target="#navHeaderCollapse">
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
   </button>
   <a class="navbar-brand" href="">My Logo</a>
</div>

jsfiddle-example