I am currently using Bootstrap 5 to design a website and have incorporated a dropdown feature into the navigation bar. On desktop, when hovering over the dropdown, it should open, while on mobile, clicking the dropdown should toggle its visibility (open/close). However, at present, it only opens and does not close on subsequent clicks.
##Test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Navbar</title>
<!-- Description meta tag for SEO -->
<link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="../css/dropdown.css" />
<!-- Additional stylesheets -->
<link
rel="stylesheet"
data-purpose="Layout StyleSheet"
title="Default"
disabled
href="/css/app-937c1ff7d52fd6f78dd9322599e2b5d4.css?vsn=d"
>
<link
rel="stylesheet"
data-purpose="Layout StyleSheet"
title="Web Awesome"
href="/css/app-wa-8d95b745961f6b33ab3aa1b98a45291a.css?vsn=d"
>
<!-- More font awesome stylesheets -->
<link
rel="stylesheet"
href="https://site-assets.fontawesome.com/releases/v6.4.0/css/all.css"
>
<link rel="icon" type="image/x-icon" href="/Bootstrap-/images/favicon-32x32.png">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light py-3 sticky-top" id="navbar-color">
<!-- Navigation bar contents -->
</nav>
<!-- NAVIGATION BAR CLOSE -->
</body>
</html>
Test.css
.navbar-light .navbar-toggler {
border: 1px solid hsl(0, 0%, 100%);
outline: none;
box-shadow: none;
}
/* CSS styles for navigation elements */
@media screen and (max-width: 576px) {
.dropdown:hover > .dropdown-menu {
display: block;
margin-top: 0;
}
}
.navbar-light .navbar-toggler {
border: 1px solid hsl(0, 0%, 100%);
outline: none;
box-shadow: none;
}
/* More CSS styles */
@media screen and (max-width: 576px) {
.dropdown:hover > .dropdown-menu {
display: block;
margin-top: 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Navbar</title>
<!-- Meta tags go here -->
<link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="../css/dropdown.css" />
<script src="https://cdn.jsdelivr.net/npm/bootstrap@dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light py-3 sticky-top" id="navbar-color">
<div class="container">
<a href="/Bootstrap-/index.html">
<img src="./src/img/logo-topnav.png" height="45" width="225" class="img-fluid"/>
</a>
<button
type="button"
class="navbar-toggler"
data-bs-toggle="collapse"
data-bs-target="#navmenu"
>
<span class="navbar-toggler-icon">
</button>
<div class="collapse navbar-collapse" id="navmenu">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a href="/Bootstrap-/index.html" class="nav-link text-white" id="nav_object">Home</a></li>
<li class="nav-item"><a href="/Bootstrap-/about.html" class="nav-link text-white" id="nav_object">About</a></li>
<li class="nav-item dropdown" id="dropdown">
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false" id="">
Services
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item text-white" href="/Bootstrap-/cctv.html">CCTV Services</a></li>
<li><a class="dropdown-item text-white " href="/Bootstrap-/datacenter.html">Datacenter Support</a></li>
<li><a class="dropdown-item text-white" href="/Bootstrap-/digital-signage.html">Digital Signage</a></li>
<li><a class="dropdown-item text-white" href="/Bootstrap-/gen-support.html">General Support</a></li>
<li><a class="dropdown-item text-white " href="/Bootstrap-/net-support.html">Network Support</a></li>
<li><a class="dropdown-item text-white " href="/Bootstrap-/pos.html">POS Services</a></li>
<li><a class="dropdown-item text-white " href="/Bootstrap-/telecom.html">Telecom Services</a></li>
</ul>
</li>
<li class="nav-item"><a href="/Bootstrap-/contact.html" class="nav-link text-white" id="nav_object">Contact</a></li>
<script>
// JavaScript goes here
</script>
<!-- Modal section -->
</nav>
<!-- NAVIGATION BAR CLOSE -->
</body>
</html>