当屏幕格式化为iphone大小时,我只是想让汉堡包图标下拉到导航栏,但它不会下拉。
我也很确定JS和jquery的位置是正确的。
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="Portfolio.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- NAVBAR -->
<nav id="myNavbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collpase" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">COTO</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#header">Home</a></li>
<li><a href="#Services">Services</a></li>
<li><a href="#pricing">Pricing</a></li>
<li><a href="#Team">Team</a></li>
<li><a href="#Clients">Clients</a></li>
<li><a href="#Contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<!-- NAVBAR END -->
</body>
</html>
答案 0 :(得分:0)
根据Bootstrap(https://getbootstrap.com/docs/4.0/components/navbar/):
data-toggle="collpase"
→data-toggle="collapse"
data-target
属性更改为ID选择器而不是类选择器: data-target=".navbar-collapse"
→data-target="#navbar"
<div class="navbar-collapse collapse" id="navbar">
答案 1 :(得分:0)
data-toggle
属性只有一点错字。此外,在尝试选择单个元素时,必须始终使用ID选择器。这是一个工作示例(已测试):
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="Portfolio.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- NAVBAR -->
<nav id="myNavbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNav">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">COTO</a>
</div>
<div class="navbar-collapse collapse" id="myNav">
<ul class="nav navbar-nav navbar-right">
<li><a href="#header">Home</a></li>
<li><a href="#Services">Services</a></li>
<li><a href="#pricing">Pricing</a></li>
<li><a href="#Team">Team</a></li>
<li><a href="#Clients">Clients</a></li>
<li><a href="#Contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<!-- NAVBAR END -->
</body>
</html>