为什么此Bootstrap导航栏的切换按钮不起作用?

时间:2018-04-18 20:56:24

标签: html twitter-bootstrap bootstrap-4

我正在尝试创建bootstrap导航栏,但切换按钮不起作用。我在body标签上使用了.sidebar-collapse类,因此当我点击切换按钮时,数据应显示在右侧。但这不会发生。有人能告诉我我的代码有什么问题吗?

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/core.js"> 
</script>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="css/now-ui-kit.css" type="text/css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font- 
awesome.min.css" rel="stylesheet" integrity="sha384- 
wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" 
crossorigin="anonymous">
<title>
    Techversity
</title>
</head>
<body class="sidebar-collapse">
<nav class="navbar navbar-expand-lg bg-primary">
<div class="container">
    <div class="navbar-translate">
        <a class="navbar-brand" href="#pablo">
           Techversity
       </a>
        <button class="navbar-toggler navbar-toggler-right" type="button" 
data-toggle="collapse" data-target="#navigation" aria-controls="navigation- 
index" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-bar bar1"></span>
        <span class="navbar-toggler-bar bar2"></span>
        <span class="navbar-toggler-bar bar3"></span>
    </button>

    </div>

    <div class="collapse navbar-collapse justify-content-end" 
 id="navigation">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="#pablo">
                    Home
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo">Link</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo">Disabled</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo"><i class="fa fa-instagram" 
aria-hidden="true"></i></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo"><i class="fa fa-youtube- 
play" aria-hidden="true"></i></a>
            </li>
        </ul>
    </div>
</div>
</nav>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

标记不正确。 div.container元素中不应该是div.navbar-translatenav.navbar元素。我tried没有它们,它有效。此外,您可以检查here标记不是Bootstrap预期的标记。

答案 1 :(得分:0)

我在你的代码中看不到bootstrap.min.js: https://getbootstrap.com/docs/4.0/getting-started/introduction/