gpt4 book ai didi

html - Bootstrap 切换菜单在移动 View 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 13:29:58 26 4
gpt4 key购买 nike

我使用 bootstrap 创建了一个测试文件。我在网页的头部调用了 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>

图片链接:http://i.stack.imgur.com/tRBaV.png

最佳答案

我更正了您的代码中的拼写错误。您写的是 'data-ctoggle' 而不是 data-toggle

正确代码: <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>

关于html - Bootstrap 切换菜单在移动 View 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com