document.addEventListener("click", function (e) {
if (e.target.id === "burger-time") {
document.querySelector('nav').classList.add('open');
document.getElementById('burger-time').style.visibility = 'hidden';
} else {
document.querySelector('nav').classList.remove('open');
document.getElementById('burger-time').style.visibility = 'visible';
}
});
#header-nav-background {
display: block;
background-color: rgb(31, 70, 189);
background-color: rgba(31, 70, 189, .5);
height: 54px;
width: 100%;
}
#header-ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(31, 70, 189);
background-color: rgba(31, 70, 189, 1);
z-index: 1200;
}
.button-style {
font-size: 20px;
font-family: 'Roboto', sans-serif;
}
#burger-time{
position: absolute;
visibility: hidden;
}
@media screen and (max-width: 669px) and (min-width: 300px) {
.header {
display: flex;
flex-wrap: wrap;
flex-direction: row;
background-color: rgb(255, 255, 255);
background-color: rgba(255, 255, 255, 1);
border-bottom: 5px solid #02b3e4;
border-bottom-style: none;
}
nav {
width: 140px;
height: 400px;
-webkit-transform: translate(-565px, 0);
-ms-transform: translate(-140px, 0);
-moz-transform: translate(-140px, 0);
-o-transform: translate(-140px, 0);
transform: translate(-140px, 0);
-webkit-transition: 0.3s ease;
-o-transition: 0.3s ease;
-moz-transition: 0.3s ease;
}
.hidden {
visibility: hidden;
}
.li .a {
display: block;
color: white;
padding: 11px 45px 19px 0;
text-decoration: none;
width: 100%;
}
/* Change the link color to rgba(31, 70, 189, 1) on hover */
.li .a:hover {
font-family: 'Roboto', sans-serif;
font-weight: 600;
color: rgb(31, 70, 189);
color: rgba(31, 70, 189, 1);
text-shadow: 1px 1px 0 black;
background-color: white;
}
.button-style {
font-size: 20px;
font-family: 'Roboto', sans-serif;
}
#header-nav-background {
display: block;
background-color: rgb(31, 70, 189);
background-color: rgba(31, 70, 189, 1);
height: 54px;
}
#burger-time{
position: absolute;
visibility: visible;
display: flex;
padding: 0 2px 2px 0;
font-size: 52px;
transform: translate(140px, 0);
color: white;
text-shadow: 2px 2px 2px black;
}
#burger-time:hover {
text-decoration: none;
color: rgb(31, 70, 189);
color: rgba(31, 70, 189, 1);
font-weight: 600;
background-color: white;
text-shadow: 1px 1px 1px black;
}
}
<div id="header-nav-background">
<nav>
<ul id="header-ul">
<li class="li button-style"><a class="a" href="index.html">Home</a></li>
<li class="li button-style">
<a class="a" href="services.html">Services</a>
</li>
<li class="li button-style"><a class="a" href="about.html">About</a></li>
<li class="li button-style">
<a class="a" href="contact.html">Contact us</a>
</li>
<i id="burger-time" class="material-icons">menu</i>
</ul>
</nav>
</div>