修复自适应导航栏

时间:2019-01-31 22:48:08

标签: html twitter-bootstrap responsive-design

我正在构建一个bootstrap4导航栏,该栏可以响应不同的平台/设备。导航栏对移动屏幕的大小没有响应。以下是模板

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1                /jquery.min.js"></script>
<title>World Visuo</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

<body>

<!-- navbar starts here -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar" aria-controls="myNavbar" aria-expanded="false" aria-label="Toggle navigation">
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 </button>
 </div>
 <a class="navbar-brand" href="#">World Visuo</a>


 <div class="collapse navbar-collapse" id="myNavbar"> 
 <ul class="nav navbar-nav navbar-right" >
 <li class="active"><a href="#">Community</a></li>
 <li class="popup1_open data-toggle="modal" data-target="#myModal"><a href="#">Sign Up</a></li>
 <li class="popup2_open"><a href="#">Login</a></li>
 </ul>
 </div>

<!--Modals Starts-->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!--modal content-->
<div class="modal-content">

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> <!--modal ends here-->

 </div>

 </nav>

 <!-- section 1 starts here-->
 <div class="container-fluid"></div><!-- section 1 ends -->

 <!-- Latest compiled JavaScript -->
 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js">               </script>
 </body>
 </html>

我希望可以通过按钮切换“社区,注册,登录”,但只会隐藏内容,但不会打开。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

您需要加载没有执行的引导程序javascript。另外,您正在使用Bootstrap 3,它不适用于jquery slim,因此您需要在jquery上使用完整版本。我相信你需要使用jQuery 2,所以我加载了它。我也使用了bootstrap 3的最新版本3.7。您还需要将navbar品牌放在navbar标头中。这里所说的只是您代码的更新版本。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>World Visuo</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<body>

<!-- navbar starts here -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">World Visuo</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar" aria-controls="myNavbar" aria-expanded="false" aria-label="Toggle navigation">
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 </button>
 </div>



 <div class="collapse navbar-collapse" id="myNavbar"> 
 <ul class="nav navbar-nav navbar-right" >
 <li class="active"><a href="#">Community</a></li>
 <li class="popup1_open"><a href="#">Sign Up</a></li>
 <li class="popup2_open"><a href="#">Login</a></li>
 </ul>
 </div>

 </div>

 </nav>

 <!-- section 1 starts here-->
 <div class="container-fluid"></div><!-- section 1 ends -->

 <!-- Latest compiled JavaScript -->
 <script
 src="https://code.jquery.com/jquery-2.2.4.min.js"
 integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
 crossorigin="anonymous"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
 </body>
 </html>