我基于Bootstrap创建了一个 hableable下拉菜单。当光标悬停在菜单标题上时,将显示一个菜单下拉菜单。当光标位于下拉菜单中时,背景颜色更改为浅紫色。在此下拉列表中单击鼠标时,背景色将更改为深紫色。我想在单击鼠标后关闭下拉菜单。我的代码没有做到我想要的。下拉菜单保持不变。我的代码和css
有什么问题?
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Bootstrap 4 Menu Hover</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<style>
/* change the color of active or hovered menu */
.nav-item .nav-link:hover,
.nav-item.active .nav-link {
color: #ffffff;
background-color: #570066;
}
/* change the color of the hovered menu item */
.dropdown-item:hover {
color: #ffffff;
background-color: #eca8f8;
}
.dropdown-item:active {
color: #ffffff;
background-color: #570066;
}
.nmt-bg-light {
background-color: white;
}
.nmt-navbar-light {
background-color: white;
}
/* custom hamburger border color */
.navbar-toggler {
border-color: rgb(243,239,6);
}
/* custom hamburger stack. note: rgba() color must be same as above */
.navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(243,239,6, 0.7)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
.dropdown:hover>.dropdown-menu {
display: block;
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg nmt-navbar-light nmt-bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent" *ngIf="authService.isLoggedIn()">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" [routerLink]="['/home']">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" [routerLink]="report" id="dropdownMenuReport" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Report
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuReport">
<a class="dropdown-item" href="#" >Report 1</a>
<a class="dropdown-item" href="#">Report 2</a>
<a class="dropdown-item" href="#">Report 3</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" [routerLink]="help" id="dropdownMenuHelp" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Help
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuHelp">
<a class="dropdown-item" [routerLink]="['/faq']">FAQ</a>
<a class="dropdown-item" [routerLink]="['/user-guide']">User Guide</a>
<a class="dropdown-item" [routerLink]="['/contact-us']">Contact Us</a>
</div>
</li>
</ul> <!-- menu bar items -->
</div> <!-- menu bar -->
</nav>
</div> <!-- container -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>