Mobile Navigation Menu Appears and Disappears When Media Query Shrinks

Whenever I shrink the page, the menu quickly pops up and then slides back down. I would prefer it not to show up at all when the page shrinks. I can't figure out why this issue is occurring.

I suspect that the problem lies with transitions on #nav rather than

input[type="checkbox"]:checked + #nav
, but I still need to have animation on #nav. I had a separate file where I worked on the mobile nav and it functioned correctly. However, things went downhill as soon as I started working with media queries.

Here's the link to the fiddle: https://jsfiddle.net/reizer/fwzsxrnt/

* {margin:0;padding:0;border:0;list-style:none;font-size:100%;font:inherit;vertical-align:baseline;}
/*RESET*/
body {font: 1em Arial, Helvetica, sans-serif;}
#wrapper {
max-width: 960px;
margin: auto;
}
#nav {
display: block;
max-height: 0em;
overflow: hidden;
transition: max-height 0.5s ease;
-webkit-transition: max-height 0.5s ease;
-moz-transition: max-height 0.5s ease;
-o-transition: max-height 0.5s ease;
}
input[type="checkbox"] {
position: absolute;
margin-top: -100em;
}
input[type="checkbox"]:checked + #nav{
max-height: 20em;
}
label {
background: #9c0;
cursor: pointer;
display: block;
overflow: auto;
padding-left: 1em;
background-color: #9C0;
background: -moz-linear-gradient(top,  #99cc00 0%, #85b100 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#99cc00), color-stop(100%,#85b100));
background: -webkit-linear-gradient(top,  #99cc00 0%,#85b100 100%);
background: -o-linear-gradient(top,  #99cc00 0%,#85b100 100%);
background: -ms-linear-gradient(top,  #99cc00 0%,#85b100 100%);
background: linear-gradient(to bottom,  #99cc00 0%,#85b100 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#99cc00', endColorstr='#85b100',GradientType=0 );
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
color: #FFF;
font-size: 1.6em;
line-height: 2.6em;
}
label:after   {
content: "\f039";
float: right;
background-color: #669900;
padding: 0.2em 0.3em 0.1em;
margin: 0.5em;
font: 1.2em FontAwesome;
border-radius: 0.3em;
-webkit-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0,0,0.3);
-moz-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0,0,0.3);
box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0,0,0.3);
}

#nav ul li a {
background: #690;
border: solid #90c12f;
border-width: 1px 0 0;
text-decoration: none;
padding: 1em;
display: block;
color: #FFF;
}
#nav ul li a:hover, #nav ul li a:active {
background: #abd728;
}
@media screen and (min-width: 479px) {
.d----onttouchshituntilthispoin----t {
}
label {
display:none;
}
#nav {
display: table;
width: 100%;
max-height: 20em;
overflow: auto;
}
#nav ul {
display: table-row;
}
#nav ul li {
display: table-cell;
}
#nav ul li a {
color: #000;
position: relative;
text-align: center;
text-indent: 20px;
border: solid #000;
border-width: 0 1px 0;
line-height: 3.4em;
padding: 0 20px 0;
transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
} #nav ul li:last-child a{border:none}
#nav ul li a:hover {
position: relative;
text-indent: 0;
padding-right: 40px;
}
#nav ul li a:before {
font-family: FontAwesome;
content: "\f078";
position: absolute;
right: 1em;
margin-top: -0.85em;
visibility: hidden;
opacity: 0;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
}
#nav ul li a:hover:before {
margin-top: 0;
visibility: visible;
opacity: 1;
}

#nav ul li a ul li {
position: absolute;
background: #FF0;
display: block;
width: 100%;
height: 0;
visibility: hidden;
opacity: 0;
border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
-webkit-border-radius: 0 0 5px 5px;
-webkit-transition: height 0.5s ease, opacity 0s ease 0.5s, visibility 0s ease 0.5s;
transition: height 0.5s ease, opacity 0s ease 0.5s, visibility 0s ease 0.5s;
-o-transition: height 0.5s ease, opacity 0s ease 0.5s, visibility 0s ease 0.5s;
-moz-transition: height 0.5s ease, opacity 0s ease 0.5s, visibility 0s ease 0.5s;
}
#nav ul li a:hover ul li {
visibility: visible;
opacity: 1;
height: 1em;
-webkit-transition: height 0.5s ease;
transition: height 0.5s ease;
-o-transition: height 0.5s ease;
-moz-transition: height 0.5s ease;
}
<div id="wrapper"><div id="logo"></div><label for="toggle">menu</label>
<input type="checkbox" id="toggle">
<div id="nav">
   <ul>
      <li><a href="#">Home<ul><li></li></ul></a></li>
      <li><a href="#">About<ul><li></li></ul></a></li>
      <li><a href="#">Products<ul><li></li></ul></a></li>
      <li><a href="#">FAQ<ul><li></li></ul></a></li>
      <li><a href="#">Support<ul><li></li></ul></a></li>
      <li><a href="#">Contact<ul><li></li></ul></a></li>
   </ul>
</div>
test
</div>

Answer №1

Simply delete the line max-height: 20em; from the CSS selector #nav when in the media query.

Check out JSFiddle for reference

* {
  margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/*RESET*/

body {
  font: 1em Arial, Helvetica, sans-serif;
}
#wrapper {
  max-width: 1200px;
  margin: auto;
}
#nav {
  display: block;
  max-height: 0em;
  overflow: hidden;
  transition: max-height 0.5s ease;
}
input[type="checkbox"] {
  position: absolute;
  margin-top: -100em;
}
input[type="checkbox"]:checked + #nav {
  max-height: 20em;
}
label {
  background: #09c;
  cursor: pointer;
  display: block;
  
  // Additional styling properties here
  
}
// More CSS code here

media screen and (min-width: 479px) {
 // Media Query CSS Code Here
}
<div id="wrapper">
 <div id="logo"></div>
 <label for="toggle">menu</label>
 <input type="checkbox" id="toggle">
 <div id="nav">
 <ul>
 <li><a href="#">Home<ul><li></li></ul></a>
 </li>
 <li><a href="#">About<ul><li></li></ul></a>
 </li>
 <li><a href="#">Products<ul><li></li></ul></a>
 </li>
 <li><a href="#">FAQ<ul><li></li></ul></a>
 </li>
 <li><a href="#">Support<ul><li></li></ul></a>
 </li>
 <li><a href="#">Contact<ul><li></li></ul></a>
 </li>
 </ul>
 </div>
 </div>
 test
</div>

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

Tips for effectively incorporating CSS classes with Booststrap and Wagtail

Currently, I am utilizing a Bootstrap theme and trying to place up to three cards horizontally on a page at one specific location. Here is the HTML code: <div class="container"> <h1 class="text-center">{{ self.title }}</h1> <d ...

Is it possible to emphasize a duration of 25 minutes on an analog clock by utilizing CSS gradients?

I am in the process of incorporating a countdown timer but with an analog clock rather than a digital one. My objective is to emphasize the next 25 minutes as a circle sector that commences from the minute hand on the clock. Here is what I have developed ...

What is the best way to prepopulate an HTML form field for email submission?

Looking for a way to prepopulate the subject field in an HTML form with To and From fields? I'd like to achieve this using JS or jQuery. I want the message to say "Hi, thanks for stopping by (followed by the rest of the message)..." just like LinkedI ...

The color of the progress bar in JS is not displaying properly

My work involves using jQuery to manipulate progress bars. The issue I am facing is defining standard colors that should be displayed on the progress bar based on the value received. Here is my code: var defaultSegmentColors = ['#FF6363', &ap ...

Issue with Navbar Header: Troubleshooting and Solutions

I'm having trouble with my navigation bar. I want to add "3" under the dropdown section and set up multiple menu items, such as Link 4. I couldn't figure out how to do this in my code... Could it be that Bootstrap doesn't support this feat ...

Unexpected behavior observed with Bootstrap popover

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Bootstrap Popover</title&g ...

Utilizing highcharts to visualize non-linear time data pulled from a CSV file

I am seeking guidance on implementing a simple graph based on data from a CSV file in web development. I lack experience in this area and have struggled to find a suitable example to follow. The CSV file contains data in the format of a unix timestamp, hu ...

Create a custom navigation bar using Bootstrap styling

I am currently attempting to create a unique Navigation Bar design using bootstrap https://i.sstatic.net/HDGFw.jpg Here is the code snippet I am working on: <div class="navbar-header"> <button type="button" class="navbar-toggle" data- ...

How can I align a div in a vertical manner if it is displayed as a circle?

This is the creation I have come up with: This is the design I am aiming for: Below is the code I have written: <div id="OR"><span style=" vertical-align: middle;background:blue;">OR</span></div> Here is the corresponding CSS: ...

Ways to modify the alignment of specific inline-block elements inside a DIV

Is there a way to align two inline-block elements to the left and one to the right without changing their display property? I am looking for a CSS solution, but would also consider using jQuery if necessary. In simple terms, I want the first two buttons ...

Properties of an Asp.NET user control referenced from a different project/dll are appearing as NULL

Attempting to transfer a common custom control to a new class library (also tried a new web project) in order for other projects to utilize it, but encountering an issue where its properties are always NULL when used in another project. Despite exploring s ...

Navigating from a Card to a new View in Angular

I am currently developing a project using Angular (latest version). Within my application, I have the functionality to dynamically generate bootstrap cards from an Order Array and display them in my "Order-Item-Component through its respective template. ...

Extracting content from concealed elements with Selenium in Python

I am currently using the Python Selenium library to scrape data from a website, but I am encountering an issue. When I click on the website to retrieve additional rows from a table, those rows appear with the classes hidden-xs hidden-sm, which makes it cha ...

Why is the decision made to simply remove an item? Is there an option to instead choose and delete the specific item?

I am facing an issue with my form where I have a function to dynamically add inputs using "append" and another button to remove the inputs added. When I use the "last-child" selector to delete the last generated div, the remove button stops working and I a ...

Tracking the email field in a React form with refs

Hey there! I'm a music engineer working on my own personal website using React. I'm currently facing an issue with creating a contact form that allows users to input a subject in a text field, a message in a textarea, and then click a "reach out" ...

Clicking on the parent page prevents the hyperlink inside the iframe from working as expected

I am having an issue with a hyperlink inside an iframe. When I click on it in the parent page, it doesn't work. Here is how it is set up: iframe.html <h1>I'm inner page!</h1> <a id="shared" class="btn" href=&q ...

Using a PHP switch case statement with an HTML multiple select dropdown

I am facing an issue with my HTML multiple select box: <option value="1">First choice</option> <option value="2">Second choice</option> <option value="3">Third choice</option> Using jQuery, ...

Determine the height of a DIV element and its contents using JQuery

In this div, there are various elements present: <div class="menuItem designMenu" id="dMenu"> <ul class="menuList menu"> <li class="menuHeader">Design</li> <li class="projectHeader">Mother</li> <li clas ...

Renew The Dining Surface

I am looking for a way to update the table content without refreshing the entire page. I am using HTML, CSS, and JavaScript to display the current data from my sqlite3 database. Any tips on how to achieve this would be appreciated. ...

How to Preserve Image Aspect Ratio within a Div Using the 'Overflow: Hidden' CSS Property

I am in the process of creating a profile page that takes inspiration from Facebook's layout design, particularly focusing on the banner and profile image combination. While my implementation looks good on desktop screens, I am facing challenges when ...