From a484584400e9b70151b5d8ea971dcc0a4cc36175 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 22 Sep 2022 21:00:49 +0100 Subject: [PATCH] Try nav menu again --- js/nav.js | 23 ++++++++++---- page-blocks/nav-menu.php | 15 +++++---- styles/style.css | 68 +++++++++++++++++++++++----------------- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/js/nav.js b/js/nav.js index 19b4753..6cbf18e 100644 --- a/js/nav.js +++ b/js/nav.js @@ -1,8 +1,19 @@ -function menuFunction() { - var hidden = document.getElementById("menu-hidden"); - if (hidden.style.display === "block") { - hidden.style.display = "none"; - } else { - hidden.style.display = "block"; +/* When the user clicks on the button, +toggle between hiding and showing the dropdown content */ +function myFunction() { + document.getElementById("myDropdown").classList.toggle("show"); +} + +// Close the dropdown menu if the user clicks outside of it +window.onclick = function(event) { + if (!event.target.matches('.dropbtn')) { + var dropdowns = document.getElementsByClassName("dropdown-content"); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + openDropdown.classList.remove('show'); + } + } } } diff --git a/page-blocks/nav-menu.php b/page-blocks/nav-menu.php index 7696b21..b763089 100644 --- a/page-blocks/nav-menu.php +++ b/page-blocks/nav-menu.php @@ -1,10 +1,9 @@ '; -echo ''; -echo ''; -echo ''; + +echo ''; diff --git a/styles/style.css b/styles/style.css index 926e8d2..2a3005a 100644 --- a/styles/style.css +++ b/styles/style.css @@ -115,43 +115,55 @@ body { cursor: pointer; } -/* Menu Styles */ +/* START MENU STYLE */ -.nav-bar { - overflow: hidden; - background-color: #3c78d8; - position: relative; -} - -.nav-bar #menu-hidden { - display: none; -} - -.nav-bar a { - position: fixed; - top: 0; - right: 0; +/* Dropdown Button */ +.dropbtn { + background-color: #3498DB; color: white; - padding: 10px 10px; - text-decoration: none; - font-size: 17px; - display: block; - /*background-color: #aac4ee;*/ + padding: 16px; + font-size: 16px; + border: none; + cursor: pointer; } -.nav-bar a.img { - display: block; +/* Dropdown button on hover & focus */ +.dropbtn:hover, .dropbtn:focus { + background-color: #2980B9; +} + +/* The container
- needed to position the dropdown content */ +.dropdown { position: relative; - max-width: 20px; - right: 0; - top: 0; + display: inline-block; } -.nav-bar a:hover { - background-color: #ddd; - color: black; +/* Dropdown Content (Hidden by Default) */ +.dropdown-content { + display: none; + position: absolute; + background-color: #f1f1f1; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; } +/* Links inside the dropdown */ +.dropdown-content a { + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; +} + +/* Change color of dropdown links on hover */ +.dropdown-content a:hover {background-color: #ddd;} + +/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */ +.show {display:block;} + +/* END MENU STYLE */ + /* Footer Styles */ footer {