Boostrap 4 Navbar不起作用

时间:2017-10-10 17:16:12

标签: css twitter-bootstrap menu

我是Bootstrap的新手。我安装了Bootstrap 4并直接从Bootstrap 4 Navbar示例代码中获取了Navbar代码,但代码没有显示导航 - 它只显示菜单图标。有人可以告诉我,我在这里做错了吗?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.css">
    <link rel="stylesheet" type="text/css" href="js/bootstrap.js">
</head>
<body>
<div class="container">
            <nav class="navbar navbar-toggleable-md navbar-light bg-faded">
                <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <a class="navbar-brand" href="#">Navbar</a>
                <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
                    <div class="navbar-nav">
                        <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
                        <a class="nav-item nav-link" href="#">Features</a>
                        <a class="nav-item nav-link" href="#">Pricing</a>
                        <a class="nav-item nav-link disabled" href="#">Disabled</a>
                    </div>
                </div>
            </nav>
 </div>
</body>
</html>

3 个答案:

答案 0 :(得分:4)

Bootstrap V4 Beta导航栏与Bootstrap V4 Alpha导航栏不同。

以下是https://getbootstrap.com/docs/4.0/components/navbar/取得的Bootstrap v4 Beta导航栏示例

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

答案 1 :(得分:2)

不确定您使用的是哪个版本的引导程序。但是你缺少Jquery CDN,它肯定会破坏引导程序。

在html doc的开头摆脱Bootstrap JS并在最后添加它。 (在引导JS之前必须引用jquery。)

<!-- 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="js/bootstrap.min.js"></script>

答案 2 :(得分:1)

您正在使用旧引导版本的导航栏。 你需要获得bootstrap 4的模板。 请点击链接:

https://getbootstrap.com/docs/4.0/components/navbar/