导航栏无法正常工作


<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="http://karinakozarova.me/Blog/pics/logo-kari.png" width = "90px"/>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right text-color">
<li><a class = "menu" href="Bloghome.html">Home</a></li>
<li><a class = "menu" href="Blogposts.html">Posts</a></li>
<li><a class = "menu" href="Blogcontact_info.html">Contact</a></li>
<li><a class = "menu" href="Blogabout.html">About</a></li>
</ul>
</div>
</div>
</nav>

以下代码在移动设备上不起作用,在另一个 SO 问题中,我读到数据目标="myNavbar"所以我做到了,但它仍然不起作用。

你给data-target一个 ID ...您需要在id之前使用#

设置

data-target="#myNavbar"

它现在应该可以工作了。

<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="http://karinakozarova.me/Blog/pics/logo-kari.png" width = "90px"/>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right text-color">
<li><a class = "menu" href="Bloghome.html">Home</a></li>
<li><a class = "menu" href="Blogposts.html">Posts</a></li>
<li><a class = "menu" href="Blogcontact_info.html">Contact</a></li>
<li><a class = "menu" href="Blogabout.html">About</a></li>
</ul>
</div>
</div>
</nav>
</body>
</html>

相关内容

  • 没有找到相关文章