Bootstrap第一行代码无法正常工作?

时间:2017-07-02 18:37:05

标签: html css twitter-bootstrap

This is my output

我不知道我做错了什么。一切都很完美。这是代码。我使用Django框架和谷歌浏览器作为浏览器。我觉得我的电脑里缺少一些东西。我不知道这是什么。因为代码完美无缺。为什么我没有完美地获得导航栏?

    <!DOCTYPE html>
{% load static %}
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="{% static 'main/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    {% block body %} {% endblock %}
    <div class="container-fluid">
        <nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <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>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
    </div>
    <h1>Hello, world!</h1>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="{% static 'main/js/bootstrap.min.js' %}"></script>
  </body>
</html>

4 个答案:

答案 0 :(得分:1)

首先,您在3.1.1的{​​{1}}和<head>底部导入了2个不同版本的jQuery,1.12。你也为<body>做了这个。

删除bootstrap.min.jsjQuery中的<head>,并将其放在bootstrap.min.js标记之前,如下所示:

</body>

然后,再试一次。希望这可以帮助。

答案 1 :(得分:1)

Image of your page

将Django链接分别替换为http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.csshttp://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js的bootstrap css和js,您的菜单确实显示正确。

您的Django链接可能出错了。我检查所有这些进口商品。例如,您已经两次导入bootstrap.min.js和jquery.min.js:在头部和身体中。

答案 2 :(得分:0)

两次连接的脚本

在头部jquery.min ....和bootstrap.min ....

之前/身体

答案 3 :(得分:0)

您需要在container-fluid之前使用nav,这样它才会填满整个屏幕,同时也会覆盖navbar