The hamburger symbol on my website is failing to show the menu options

I'm having trouble getting my burger icon to display the navigation menu on mobile devices. I've tried adjusting functions in my JavaScript and tweaking the media queries in my CSS file, but the menu still won't show up when the page size is reduced to 812px or less.

Here's a look at my HTML:

<header>
          <nav>
            <div class="aw-container">
              <a href="Home.html"><img class="logo" src="img/logo.jpg"  width="60" height="50" alt="logo"></a>
              <div id="nav-class" class="aw-burger-open">
              <ul class="aw-navigation">
                <li><a class="aw-section-home" href="#">Home</a></li>
                <li><a class="aw-section-blog" href="#aw-blog">Blog</a></li>
                <li><a class="aw-section-link" href="#aw-contact">Travel</a></li>
                <li><a class="aw-section-newsletter" href="#aw-newsletter">Contact</a></li>
                <li><a class="aw-section-study" href="#aw-study">Planning</a></li>
                <li><a class="aw-section-search" href="aw-search">Search</a></li>
              </ul>
            </div>
                  <form class="searchbar" method="get">
                    <input type="text" id="s" placeholder="Search" name="search">
                    <div class=" close-icon">
                      <button type="button"><i class="fa fa-close"></i></button>
                  </div>
                </form>
                <div id = "burger-menu" class="burger" onclick="myFunction(this);toggleDropdown(this);">
                  <div class="bar1"></div>
                  <div class="bar2"></div>
                  <div class="bar3"></div>
                </div>
              </nav>
          </header>

And here's the relevant CSS:

@media screen and (max-width: 812px) {

    ul.aw-navigation{
      visibility: hidden;
    }

    #nav-class{
      display: flex;
      flex-direction: column;
    }

    /*Burger Menu */

    .burger {
      display: inline-block;
      cursor: pointer;
    }

    .bar1, .bar2, .bar3 {
      width: 20px;
      height: 2px;
      background-color: #333;
      margin: 6px 0;
      transition: 0.4s;
    }

    .change .bar1 {
      -webkit-transform: rotate(-45deg) translate(-4px, 3px);
      transform: rotate(-45deg) translate(-4px, 3px);
    }

    .change .bar2 {opacity: 0;}

    .change .bar3 {
      -webkit-transform: rotate(45deg) translate(-8px, -8px);
      transform: rotate(45deg) translate(-8px, -8px);
    }

}

Finally, here's the JavaScript code that controls the burger menu:

//Burger//

function myFunction(x) {
  x.classList.toggle("change");
}

function toggleDropdown() {
  document.getElementById("nav-class").classList.toggle("show");
}

window.onclick = function(event) {
  if (!event.target.matches('.burger')) {
    var dropdowns = document.getElementById("nav-class");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}

I have not encountered any errors in the console while debugging this issue. The myFunction(), which changes the burger icon to an X symbol, seems to be working fine, but the toggleDropdown() function is not functioning as expected. Any help would be greatly appreciated!

Answer №1

1- Remember to close the <div class="aw-container"> tag correctly. 2- Don't forget to add the "show" class. 3- It's important to note that document.getElementByID always returns a parameter, so it cannot be used in a for loop.

Answer №2

It appears that the show class is missing in the CSS code.

.show ul.aw-navigation{
visibility: visible;

}

I attempted to use this code pen:

https://codepen.io/sarang13579/pen/MMPmyx

You can explore more visually appealing navigation menu implementations on w3schools or codepen by conducting a simple search.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The 'checked' property cannot be bound to 'mat-button-toggle' as it is not recognized as a valid property in Angular 9

I am encountering an issue with my Angular 9 application. I have integrated angular-material and imported the MatCheckboxModule correctly in the module. Here is the version of the material package I am using: "@angular/material": "^10.2.0&q ...

Angular loop is unable to detect changes in the updated list

My Angular application is facing a peculiar issue that I can't seem to figure out. // Here are the class attributes causing trouble tenants: any[] = []; @Input() onTenantListChange: EventEmitter<Tenant[]>; ngOnInit(): void { this. ...

What is the best way to update the color of an fa icon when an error message is displayed using PHP

I am facing an issue with my form where error messages are displayed on certain input fields. The error messages show up correctly, but I want to change the color of the "fa" icon in the field when its corresponding error message appears. My goal is to ma ...

Updating a $scope variable within a loop in AngularJS

Attempting to modify a $scope variable: Example: $scope.variable_1 $scope.variable_2 ... Desired way of updating it: for (i=0; i<2; i++) { $scope.variable_$i = 1; } Wanting to access "$scope.variable_1" using the "i" index in each loop. Any ...

Sending data from a child component to a parent component in React

Trying to figure out how to pass the returned value of function appColor from the WeatherForecast component into a property, and then passing that property from WeatherForecast to the className of the app component. I'm new to React, so not sure how t ...

The initial invocation of the JavaScript function did not run

In my Grails view, I have a script tag set up like this: <script type="text/javascript"> /* the first setInterval */ setInterval( function() { console.log("Test..."); }, 5000 ); setInterval( ...

Select certain properties from an object using JavaScript

I am looking to extract a specific subset of values from an object in a specific order. const obj = { a: 1, b: 2, c: 3, d: 4 }; const values = extractValues(obj, ['a', 'd']); // extracted values [1, 4] While I can create my own extrac ...

How to rename a class of an image tag using jQuery

I need to update the class name in my image tag <img src="img/nex2.jpeg" class="name"> When hovering over with jquery, I want to add a new class to it. After hovering, the tag should appear as follows: <img src="img/nex2.jpeg" class="name seco ...

What is the process for setting up a server with Node.js?

After diving into my nodejs studies, I hit a roadblock at the point where I was supposed to create a server. Here's the code snippet for this particular script: var http = require('http'); // Import Node.js core module var server = http.cre ...

Automatically reset the form after submission in CakePHP 1.3

I've encountered an issue with my report form that is linked multiple times on a page to a jQuery dialog box. To prevent cross-posting, I added a random string to the submission process. After successfully submitting the form on a single page access, ...

"Using Selenium in Python to navigate Google's search results and view the

Hello, I am new to using selenium and I have a specific task in mind. I would like to scrape the address search results from Google that are displayed on the sidebar column. I have successfully managed to use selenium to conduct searches on Google and land ...

How can you modify the encapsulation of a third-party component in an Angular application?

Utilizing AngularElements with native encapsulation allows bs4 components to be used in a bs3 project. For example: @Component({ selector: 'app-my-button', templateUrl: './my-button.component.html', encapsulation: ViewEncapsulati ...

What is the best way to create a footer in this scenario and is there a method to perfectly center an

What is the best way to position the footer at the bottom of the page without overlapping the top content? Is there a method to center both the height and width of the header element on the page? Can you review the layout of this webpage and provide feed ...

After executing grunt serve, Bower issues a warning for jquery stating "not injected"

Recently, I had to clone a project and rebuild bower packages. It seems that jQuery has been updated, causing a warning to appear: Warning: Please check the "app/bower_components/jquery" folder for the necessary file and manually include it in your ...

Analyzing string values in Cypress

When attempting to compare two values within a page and make an assertion, my goal is to retrieve the value of one text element and compare it with another value on the same page. While I find this process straightforward in Java/selenium, achieving the ...

What goes on behind the scenes of Angular interpolation with scripts?

I set up a variable called test = '<script>alert()</script>'. I then inserted this variable into an Angular component using interpolation like so: <div>{{ this.test }}</div>. However, instead of rendering properly, it just ...

Is there a way to programmatically access the title of a TitledPane in JavaFX without using CSS?

Is there a way to set the title of a TitledPane to bold in Java code without using CSS? I created a TitledPane and I want the title's font weight to be bold. This is what I tried: TitledPane Rootpane = new TitledPane(); Rootpane.setText("Options"); ...

Setting the backEnd URL in a frontEnd React application: Best practices for integration

Hey there - I'm new to react and front-end development in general. I recently created a RESTful API using Java, and now I'm wondering what the best way is to specify the backend URL for the fetch() function within a .jsx file in react. Currently, ...

Setting up the CSS loader in a Vue.js project using webpack

I am currently working on a new vue-cli project and have successfully installed the Pure.CSS framework using npm install purecss --save. However, I am struggling to seamlessly integrate, import, or load the css framework into my project. I am unsure of whe ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...