导航栏在较新版本的bootstrap(v3.3.6)中不起作用,它的问题是javascript部分无法像切换到移动视图和下拉列表那样工作。
当我用V3.0的bootstrap替换它时,代码工作得非常好,但在与3.3.6(CDN和离线)一起使用时不起作用。我已经交叉检查了拼写和目录错误。
<!DOCTYPE html>
<html>
<head>
<title>Guru Prasad - Freelance</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="includes/css/style.css">
<script src="includes/js/modernizr-2.6.2.min.js"></script>
</head>
<body>
<div class="navbar fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mobile-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Guru Prasad</a>
</div> <!-- Navbar-Header -->
<div class="navbar-collapse collapse">
<ul class="navbar nav">
<li class="active">Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul> <!-- End Navbar-nav -->
</div> <!-- End Navbar-collapse -->
</div> <!-- End Container -->
</div> <!-- End Navbar -->
<!-- //Javascript -->
<script type="text/javascript" src="includes/js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="includes/js/script.js"></script>
</body>
</html>
答案 0 :(得分:0)
根据您提供的代码(如果您在默认情况下执行某些操作,则需要说明这一点)我无法看到它们是如何实际工作的。
您没有将数据目标(data-target="#mobile-collapse"
)属性附加到 navbar-collapse div(<div class="navbar-collapse collapse" id="mobile-collapse">
)。
相同的HTML适用于使用 v3.0 和 v3.3.6 的以下示例。请参阅Navbar文档。
工作3.0示例
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mobile-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Guru Prasad</a>
</div>
<div class="navbar-collapse collapse" id="mobile-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="">Portfolio</a>
</li>
<li><a href="">About</a>
</li>
<li><a href="">Contact</a>
</li>
</ul>
</div>
</div>
</div>
工作3.3.6示例
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mobile-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Guru Prasad</a>
</div>
<div class="navbar-collapse collapse" id="mobile-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="">Portfolio</a>
</li>
<li><a href="">About</a>
</li>
<li><a href="">Contact</a>
</li>
</ul>
</div>
</div>
</div>