我使用bootstrap创建了一个测试文件。我在网页的head部分调用了bootstrap.min.css。
另外,在关闭body标签之前,我调用了几个JavaScript文件。
但是现在我要创建一个切换菜单,这将成为一个下拉菜单,当在移动版本中看到时,切换按钮不起作用。这是切换按钮的代码。
我想知道背后的原因是什么。为什么切换按钮无法正常工作?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Testing of Bootstrap</title>
<meta name-"viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/home/user/Testing/bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-ctoggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Themes<b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Admin & Dashboard</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<h1>Testing H1</h1>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">Box 1</div>
<div class="col-md-4 col-sm-6">Box 2</div>
<div class="col-md-4 col-sm-6">Box 3</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 4</div>
<div class="col-md-4 col-sm-6">Box 5</div>
<div class="col-md-4 col-sm-6">Box 6</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 7</div>
<div class="col-md-4 col-sm-6">Box 8</div>
<div class="col-md-4 col-sm-6">Box 9</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 10</div>
<div class="col-md-4 col-sm-6">Box 11</div>
<div class="col-md-4 col-sm-6">Box 12</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="/home/user/Testing/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
答案 0 :(得分:2)
您的代码中存在拼写错误,我对其进行了更正。您写了&#39; data-ctoggle&#39; 而不是数据切换
正确的代码: <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Testing of Bootstrap</title>
<meta name-"viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="http://getbootstrap.com/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://getbootstrap.com/examples/navbar/navbar.css">
</head>
<body>
<nav class="navbar navbar-default" >
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Themes<b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Admin & Dashboard</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1>Testing H1</h1>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">Box 1</div>
<div class="col-md-4 col-sm-6">Box 2</div>
<div class="col-md-4 col-sm-6">Box 3</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 4</div>
<div class="col-md-4 col-sm-6">Box 5</div>
<div class="col-md-4 col-sm-6">Box 6</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 7</div>
<div class="col-md-4 col-sm-6">Box 8</div>
<div class="col-md-4 col-sm-6">Box 9</div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4 col-sm-6">Box 10</div>
<div class="col-md-4 col-sm-6">Box 11</div>
<div class="col-md-4 col-sm-6">Box 12</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
</body>
</html>
&#13;
答案 1 :(得分:0)
检查此行以查看其是否正确指出
<script src="/home/user/Testing/bootstrap/js/bootstrap.min.js"></script>
或
从http://getbootstrap.com/getting-started/#download
下载核心文件将javascript代码替换为以下
<script src="../../dist/js/bootstrap.min.js"></script>
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>