Does the responsive navigation vanish when the size is changed?

I've encountered a glitch with my responsive drop-down navigation that's affecting its functionality.

Here's the scenario: when the page loads, everything works fine. But if I resize the page to reveal the mobile nav (hamburger menu), it behaves strangely. The issue arises

  • If I switch to mobile view, open the menu, and then resize without closing it, the nav remains visible.

  • If I go to mobile view, open the menu, close it, and then resize back to full screen, the nav disappears.

I've shared some basic HTML, my JS function, and a link to the site in question below.

HTML

<div class="navigation">
  <div class="container1">
    <a class="nav-logo" href="index.html"><img src="img/logo.svg"></a>
    <div class="mobile">
      <ul class="menu nav-left">
        <a href="html/main-pages/portfolio.html"><li class="button">Work</li></a>
        <a href="html/main-pages/resume.html"><li class="button">Resume</li></a>
        <a href="html/main-pages/contact.php"><li class="button">Contact</li></a>
      </ul>

      <ul class="menu nav-right">
        <a href="#"><li class="button"><i class="fa fa-twitter"></i></li></a>
        <a href="#"><li class="button"><i class="fa fa-codepen"></i></li></a>
        <a href="#"><li class="button"><i class="fa fa-linkedin"></i></li></a>
        <a href="#"><li class="button"><i class="fa fa-behance"></i></li></a>
        <a href="#"><li class="button"><i class="fa fa-github"></i></li></a>
      </ul>
    </div>

    <span class="nav-toggle"><a href="#"><i class="fa fa-bars"></i></a></span>
  </div>
</div>

JS

 $( document ).ready(function(){
        $(".nav-toggle").click(function(){
        $(".mobile").slideToggle(500);

        });
});

You can experience the problem firsthand on this website. Thank you for any assistance - feel free to ask any questions!

For reference, here is the jsfiddle

Answer №1

The reason behind this issue is that when you close the menu on a mobile device, the .mobile class will have a display value of none. One way to solve this problem is by using the !important declaration.

@media { /* add your specific desktop media query */
  .mobile {
    display: block !important;
  }
}

Answer №2

@media (min-width: 480px) {
    .mobile {visibility: visible !important;}
}

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 "click" event is only effective for a single use

I am looking for a way to trigger the click event more than once in my project. I attempted using "live" but it didn't work as expected. There are 2 other similar scripts in this Django project. If you have any suggestions on improving this project, p ...

Issue with Angular: RouterLinkActive fails to work properly with formControlName

I am currently working on a vertical navigation bar that allows the user to navigate to different components. However, I am facing an issue where when I click on a list item, it's supposed to be active but I have to click on it to navigate to the comp ...

Enhance the functionality of your Rails application by implementing Ajax or jQuery to asynchronously load table elements separately from the page

Currently, I am facing an issue with a page that displays a list of user sites. The problem lies in the fact that I am making an API call for each site to check its status, which is causing the page to load very slowly. To address this issue, I would like ...

Retrieve the targeted row from the table and then employ a function

Here is a datatable that I am working on: http://jsbin.com/OJAnaji/15/edit I initially populate the table with data and display it. Then, I add a new column called "kontrole." data = google.visualization.arrayToDataTable([ ['Name', &apo ...

The design of the page is structured around Semantic-UI Grid, and unfortunately, the spacing between elements cannot

Currently, I'm in the process of developing a web application with the help of semantic-ui. The primary objective is to design a layout that comprises a sidebar along with a main content area. Initially, I assumed that utilizing grid would be the most ...

Using Selenium in Java to extract text from an h1 tag

Although I am familiar with the method .getAttribute("innerHTML") for retrieving the value of a h1 tag, my HTML structure is a bit different: https://i.sstatic.net/RVaMM.png While I am able to locate the h1 tag, I am facing difficulty in accessing its inn ...

Attempting to superimpose a CSS triangle arrow onto a Google Map

I'm currently working on incorporating a CSS arrow on top of a Google map as a design element. The concept involves a horizontal stripe with a downward arrow placed halfway through, and I aim to have this arrow overlay the Google map. Here is a snipp ...

Enabling Autoplay for HTML Videos on Safari iOS 14.2

Recently, I've observed that my autoplay videos are not functioning on iPhone iOS 14.2. Surprisingly, everything was working fine prior to this version. Is there anyone familiar with a solution or workaround for this issue? Perhaps there's a met ...

Retrieve the link of a nearby element

My goal is to create a userscript that has the following functionalities: Add a checkbox next to each hyperlink When the checkbox is clicked, change the state of the corresponding hyperlink to "visited" by changing its color from blue to violet. However ...

What is the best way to retrieve the responseText using the jQuery.getJSON method within JavaScript?

I am currently facing an issue where I am attempting to retrieve information from a JSON file located in my directory by utilizing the jQuery.getJSON method. Unfortunately, when I try to access the object shown in the image, I am unable to extract the resp ...

The function Yii2 isAjax returns a boolean value of false

Encountered an issue while attempting to run some code, even though it worked previously. Using AJAX to execute the code, but it resulted in a 500 error. Came across several posts with similar issues and their solutions, but none of them resolved the iss ...

Refresh your page with JQUERY and location.reload() callback

Is it possible to have a callback after using location.reload() with JQUERY to refresh the page when a user changes language? Although it refreshes the page, I am wondering if it might be possible to have a callback function as well. I would appreciate a ...

Trouble with Div Alignment in Web Browsers: Firefox vs. Google Chrome

I have encountered an issue with the layout of my website when using the Div element. While it appears correctly in Internet Explorer, the display gets distorted in Firefox and Google Chrome when the div is expanded. I have searched online for solutions b ...

"The JavaScript code included in the index.html file is not functioning as expected when called in the main.js file within a

Here is the index.html code for a simple VueJS app that includes a widget from netvibes.com. The widget code is added in the html file and functioning properly. <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC " ...

Floating above a divided rectangle div

Imagine a rectangular div divided into two parts, each part forming an L shape (as illustrated below), with region 1 representing the left-side L and region 2 representing the right-side L. I am interested in changing the background color of region 1 on h ...

Utilize the JavaScript Email Error Box on different components

On my website, I have implemented a login system using LocalStorage and would like to incorporate an error message feature for incorrect entries. Since I already have assistance for handling email errors on another page, I am interested in applying that sa ...

Issue with CSS min-height causing divs to not align properly

My CSS Code includes media queries to adjust the layout: .clearfloat { clear: both; font-size: 1px; height: 0; line-height: 0; } .box-container { width:100%; text-align:center; } .icon-box { width:32%; max-width:500px; ...

Safari is causing issues with HTML5 Video playback

I have a client with a media-heavy website containing numerous video and audio files. While the videos load perfectly on Chrome, Firefox, and IE, they do not load on Safari for Windows. Here's a snippet of the code: <video controls="controls" type ...

Deploying a React application to Heroku or GitHub pages can sometimes alter the appearance of styles and CSS

As a newbie to coding, I've managed to create multiple full-stack apps, but I've encountered a frustrating issue each time I deploy them to Heroku or GitHub Pages. Every element on the page seems to shrink in size compared to what it was on my lo ...

Discovering the id of the current active tabpane is possible by using

Is there a way to retrieve the id of the currently active tab-pane every time I switch tabs on my page? Depending on which tab-pane is active (tab-pane1, tab-pane2, tab-pane3), I want to store the respective value (tab-pane1 = 1 and so on) in a variable an ...