Bootstrap navbar未对齐

时间:2016-02-18 15:11:27

标签: twitter-bootstrap-3 navbar

出于某种原因,我的Navbar似乎有0个顶部填充,并略微偏向右侧。

HTML几乎是一个直接复制&从例子中粘贴,我不能为我的生活弄清楚为什么它不起作用。

Messed up navbar

<%@ Master Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>Main master</title>
</head>
<body>
    <div class="container">
        <div class="container">
           <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <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>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#">Test Demo</a>
                    </div>
                    <div class="collapse navbar-collapse" id="navbar">
                        <ul class="nav navbar-nav">
                            <li><a href="#">GitHub</a></li>
                            <li><a href="#">NuGet</a></li>
                            <li class="dropdown">
                                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Demos <span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">demo</a></li>
                                    <li><a href="#">demo</a></li>
                                </ul>
                            </li>                       
                        </ul>                                          
                    </div>
                </div>
            </nav>
        </div>

    <div class="container">
        <asp:ContentPlaceHolder ID="ContentSection" runat="server">
        </asp:ContentPlaceHolder>
    </div>

</div>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

你有两个<div class="container"></div>,它们都有一个偏移量。删除其中一个,看看是否能解决您的问题。

<%@ Master Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>Main master</title>
</head>
<body>
    <div class="container">
       <nav class="navbar navbar-default">
            <div class="container-fluid">
                <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>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">Test Demo</a>
                </div>
                <div class="collapse navbar-collapse" id="navbar">
                    <ul class="nav navbar-nav">
                        <li><a href="#">GitHub</a></li>
                        <li><a href="#">NuGet</a></li>
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Demos <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#">demo</a></li>
                                <li><a href="#">demo</a></li>
                            </ul>
                        </li>                       
                    </ul>                                          
                </div>
            </div>
        </nav>

        <asp:ContentPlaceHolder ID="ContentSection" runat="server">
        </asp:ContentPlaceHolder>
    </div>


    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</body>
</html>

答案 1 :(得分:0)

对于某些属性,

Bootstrap似乎需要自定义.css文件,在这种情况下,导航栏顶部处理由&#34; navbar.css&#34;

处理
body {
  padding-top: 20px;
  padding-bottom: 20px;
}

.navbar {
  margin-bottom: 20px;
}

创建此文件并将其链接到标题似乎可以解决问题。