I;ve tried to create a mobile navbar (hamburger) but it’s not working properly.
For some reason the mobile navbar is displaying “About Eco Bunny” on the index page and the hamburger button appears to not work.
Here is the html code for the navbar. In fareness, I have tried to adapt code from W3).
<div class="topnav" id="myTopnav">
<div class="dropdown">
<button class="dropbtn">EPC and Retrofit info
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="EPC-details-eco-bunny.html">Information about EPCs</a>
<a href="retrofit-assessment-eco-bunny.html">Information About Retrofit Assessments</a>
<!-- <a href="#">Link 3</a> -->
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Prices and Book
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="book-EPC-eco-bunny.html">EPC - Energy Proficiency Certificate</a>
<a href="book-Retrofit-assesment">Retrofit Assessment</a>
</div>
<div class="dropdown">
<a href="about-eco-bunny.html">About Eco Bunny</a>
<a href="contact">Contact Us</a>
</div>
</div>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
</div>
Here is the css code for mobiles (nav works fine on my laptop -full screen).
@media screen and (max-width: 600px) {
.grid-item1 img {
display: none;
}
.grid-item2 img{
display: none;
}
.logo img {
position: absolute;
top: 15px;
margin: auto;
}
.grid-container {
display: grid;
grid-template-columns: 20% 80%;
grid-template-rows: 100px;
/*height: 170px; */
gap: 5px;
/* background-color: rgba(255,90,205,0.1); */
}
.topnav a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
z-index: 1;
}
}
@media screen and (min-width: 600px) {
.logo img {
display: none;
}
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
/* position: absolute; */
right: 0;
top: 0;
z-index: 1;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 90%;
text-align: left;
margin: auto;
}
}
@media screen and (max-width: 600px) {
.grid-item1 img {
display: none;
}
.grid-item2 img{
display: none;
}
.logo img {
position: absolute;
top: 15px;
margin: auto;
}
.grid-container {
display: grid;
grid-template-columns: 20% 80%;
grid-template-rows: 100px;
/*height: 170px; */
gap: 5px;
/* background-color: rgba(255,90,205,0.1); */
}
.topnav a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
z-index: 1;
}
}
@media screen and (min-width: 600px) {
.logo img {
display: none;
}
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
/* position: absolute; */
right: 0;
top: 0;
z-index: 1;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 90%;
text-align: left;
margin: auto;
}
}
here is the url
Can you let me know what I need to do to correct this?