Bootstrap导航栏的行为与预期不符

时间:2016-09-12 17:25:28

标签: jquery html css twitter-bootstrap

我正在尝试从bootstrap教程中最简单的示例 - 页眉,导航栏。   但是当标题工作正常时,导航栏显示不正确。

我有一个project_name文件夹,里面是:

project_name
        bootstrap
                 css: bootstrap.css, bootstrap.min.css, bootstrap-         
                     responsive.css, bootstrap-responsive.min.css
                 img
                 js: bootstrap.js, bootstrap.min.js, jquery.js

        index.html

所以,bootstrap和jquery似乎是有序的,index.html代码似乎也可以。

index.html:

     <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Basic Bootstrap Template</title>
        <link rel="stylesheet" type="text/css"      
    href="bootstrap/css/bootstrap.min.css">
   </head>
    <body>
       <!-- HEADER -->
        <div class="page-header">
             <h1 align="center">Some title
             <small>some subtitle</small>
             </h1>
         </div>
         <!-- HAVBAR-->
            <nav class = "navbar navbar-inverse" role ="navigation">

                        <div class="container">
                                <a class="navbar-brand" href="#">NAVBAR</a>
                        </div>

                        <div class = "navbar-header">

                                <ul class = "nav navbar-nav">
                                        <li><a href="#">Home</a></li>
                                        <li><a href = "#">SVN</a></li>
                                </ul>
                        </div>
            </nav>


                <script src="bootstrap/js/jquery.js"></script>
                <script src="bootstrap/js/bootstrap.min.js"></script>
    </body></html>

它提供:this result

我无法弄清楚出了什么问题......

我希望得到类似的结果(但不同的文字和反色): result from tutorial

3 个答案:

答案 0 :(得分:3)

将Navbar放在顶部。

试试这个:

   <!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap Template</title>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/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.7/js/bootstrap.min.js"></script>
</head>

<body>
       <!-- HEADER -->
       <nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">NAVBAR</a>
    </div>
    <ul class="nav navbar-nav">
      <li><a href="#">Home</a></li>
      <li><a href="#">SVN</a></li>
    </ul>
  </div>
</nav>

</body>
</html>

答案 1 :(得分:1)

错误位于<div class = "navbar-header">,因为它应该与徽标而不是列表相关联。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  
</head>
<body>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Page 1</a></li>
      <li><a href="#">Page 2</a></li>
    </ul>
  </div>
</nav>
  <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.7/js/bootstrap.min.js"></script>

</body>
</html>

答案 2 :(得分:1)

如果您希望您的设计看起来与您附加的图像完全相同,则只需排除此代码块

         <div class="page-header">
            <h1 align="center">Some title
            <small>some subtitle</small>
            </h1>
         </div>

排除此代码会为您提供与附加图像中的UI相似的UI。有关导航栏的其他基本教程,请查看此站点:http://www.w3schools.com/bootstrap/bootstrap_navbar.asp

希望这有帮助!