这是我使用bootstrap的html模板。但是下拉菜单在chrome中不起作用,但它在代码播放等其他平台中起作用。
这是html代码
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<h1 class="navbar-brand">Portfolio</h1>
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="">About Me</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact Me</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Projects
</a>
<div class="dropdown-menu bg-dark" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="">Action</a>
<a class="dropdown-item" href="">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>
您在结束body标记之前缺少bootstrap.js
https://getbootstrap.com/docs/4.6/getting-started/introduction/#quick-启动
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<h1 class="navbar-brand">Portfolio</h1>
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="">About Me</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact Me</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Projects
</a>
<div class="dropdown-menu bg-dark" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="">Action</a>
<a class="dropdown-item" href="">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
您应该在文件底部添加一个JQuery CDN:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>