Bootstrap导航与内容不对齐

时间:2013-08-30 16:41:27

标签: twitter-bootstrap

为什么内容与使用Bootstrap 3.0.0的品牌不一致?我怎样才能将这些对齐?

enter image description here

这是我的HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        <meta name="viewport" content="width=device-width initial-scale=1.0">
        <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="css/app.css" rel="stylesheet">
    </head>
    <body>
        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <span class="navbar-brand">Brand</span>
                </div>
            </div>
        </div>
        <div id="main-region" class="container">
            <p>Content</p>
        </div>

        <script data-main="js/main" src="bower_components/requirejs/require.js"></script>
        <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>    
    </body>
</html>

这是app.css:

body {
    padding-top: 60px;
}

1 个答案:

答案 0 :(得分:6)

您的navbar DIV需要嵌套的container DIV才能与其他内容保持一致。

查看this example

它使用以下来源:

<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="container"> <!-- You need this DIV for alignment -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</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 class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
          <form class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </div>

    <div class="container">
        <!-- Main content goes here -->
    </div>
</body>