Try nav menu again

This commit is contained in:
Fred Boniface 2022-09-22 21:00:49 +01:00
parent 42f2afe2e9
commit a484584400
3 changed files with 64 additions and 42 deletions

View File

@ -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');
}
}
}
}

View File

@ -1,10 +1,9 @@
<?php
echo '<div class="nav-bar">';
echo '<div id="menu-hidden">';
echo '<a href="/">Home</a>';
echo '<a class="nav-bar-hidden" href="/issue.php">Report Issue</a>';
echo '<a class="nav-bar-hidden" href="/help.php">Help</a>';
echo '</div>';
echo '<a href="javascript:void(0);" class="menu-icon" onclick="menuFunction()">';
echo '<img src="/assets/icons/menu.png"></img>';
echo '<div class="dropdown">';
echo ' <button onclick="myFunction()" class="dropbtn">Dropdown</button>'
echo ' <div id="myDropdown" class="dropdown-content">';
echo ' <a href="#">Link 1</a>';
echo ' <a href="#">Link 2</a>';
echo ' </div>';
echo '</div>';

View File

@ -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 <div> - 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 {