Menu items on the responsive design are vanishing

I am facing an issue with my sample menu layout. It appears fine on desktop view, but when I switch to a smaller window size of 480px, the items from About to Contact disappear when I hover away from the last item in the .has-children class. It seems like the menu is not expanding enough to display all the items.

I have provided a snippet and would greatly appreciate any guidance you can offer. I have been attempting to modify the .has-children class without success so far.

Thank you in advance for your help.

Link to Codepen layout

.has-children ul {
        display: none;
        width: 100%;
      }
      nav ul li:hover ul,
      .has-children ul .has-children:hover ul {
        display: flex;
        flex-direction: column;
      }

html,body,nav, ul, li, a, span{
  margin:0; padding:0;
}
body{
  font-family:helvetica;
  font-size:16px;
}
nav ul {
  background-color:#444;
  display:flex;
  flex-direction:column;
}
nav ul li{
  list-style-type: none;
}
nav ul li a{
  padding:.8rem 1rem;
  display:block;
  text-decoration: none;
  color:#f9f9f9;
}
nav ul li:hover{
  background:rgba(0,0,0, .25);
}

.arrow{
  font-family:FontAwesome;
  float:right;
}
.arrow-down::after{
  content:"\f107";
}
.arrow-right::after{
  content:"\f105";
}


@media only screen and (max-width:480px){
  .has-children ul {
        display: none;
        width: 100%;
        position: absolute;
      }
      nav ul li:hover ul,
      .has-children ul .has-children:hover ul {
        display: flex;
        flex-direction: column;
      }
      .has-children ul li a {
        padding-left: 2rem;
      }
      .has-children ul .has-children ul a {
        padding-left: 3rem;
      }
      nav ul li {
      list-style-type: none;
    }
      .arrow-down::after {
        content: "\f107";
      }
}

@media only screen and (min-width:480px){
  nav ul{
    flex-direction:row;
/*     justify-content:flex-end; */
  }
  nav ul li{
    position:relative;
    flex:1 0 auto;
    text-align:left;
  }
  .has-children ul, .has-children ul .has-children ul{
    display:none;
    width:100%;
    position:absolute;
  }
  .has-children ul .has-children ul{
    left:100%;
    top:0;
  }
  nav ul li:hover ul,  .has-children ul .has-children:hover ul{
     display:flex;
    flex-direction:column;
  }
  
}
<nav>
  <ul>
    <li class="has-children"><a href="#">Home
      <span class="arrow arrow-down"></span>
      </a>
       <ul>
        <li><a href="#">Item - 1 </a></li>    
        <li><a href="#">Item - 2 </a></li>
        <li class="has-children"><a href="#">Item - 3
          <span class="arrow arrow-down arrow-right"></span>
          </a>
           <ul>
            <li><a href="#">Item - 1 </a></li>    
            <li><a href="#">Item - 2 </a></li>
            <li><a href="#">Item - 3</a></li>
            <li><a href="#">Item - 4 </a></li>
            <li><a href="#">Item - 5 </a></li>
          </ul>
         </li>
        <li><a href="#">Item - 4 </a></li>
        <li><a href="#">Item - 5 </a></li>
      </ul>
    
    </li>    
    <li><a href="#">About</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

Answer №1

If you're looking to ensure your website is responsive, the top recommendation is using BootStrap. It's the best and easiest tool for the job! Why not give it a try?
You can download the Bootstrap files from the link provided below:
https://getbootstrap.com/docs/4.0/getting-started/download/
From this link, make sure to download the compiled CSS and JS files, which consist of a CSS file and a JavaScript file. To include these files in the HTML header tag, use the code snippet provided:

<head>
  <title> Website Title </title>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link rel="stylesheet" href="filename.css">
  <script src="filename.js"></script>
</head>

For information on creating a collapsing navigation bar with Bootstrap, check out the following links:
https://www.w3schools.com/bootstrap4/bootstrap_navbar.asp and https://www.w3schools.com/bootstrap4/tryit.asp?filename=trybs_navbar_collapse&stacked=h



Hopefully, this information proves helpful to you!

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

Generate an image, PDF, or screenshot of a webpage with the click of a button

I've been searching for a solution that would enable users to click a button and save an image or PDF of the current page. The content on the page is dynamic and dependent on user input, resulting in sequences displayed in various colors. I'm loo ...

Deactivate input areas while choosing an option from a dropdown menu in HTML

I've been working on creating a form and have everything set up so far. However, I'm looking to disable certain fields when selecting an option from a dropdown list. For instance, if the "within company" option is selected for my transaction typ ...

Create a boundary behind the title on a see-through backdrop

How can I create a design where there is a line to the left and right of a headline? Usually, I would use border-top on the surrounding element and style the headline with some CSS properties like this: h2 { margin-top: -10px; padding: 0 5px; b ...

Is there a smooth and effective method to implement a timeout restriction while loading a sluggish external file using JavaScript?

Incorporating content from an external PHP file on a different server using JavaScript can sometimes be problematic. There are instances where the other service may be slow to load or not load at all. Is there a method in JavaScript to attempt fetching th ...

Looking for a way to keep the mobile ad unit fixed at the bottom of the screen

I am currently working on incorporating a 320x50 mobile ad into the mobile version of my website. The goal is to have the ad fill the entire width of a mobile device. However, the issue I'm facing is that the ad appears small and does not stretch acro ...

Steps for creating a herringbone design on an HTML canvas

Seeking Help to Create Herringbone Pattern Filled with Images on Canvas I am a beginner in canvas 2d drawing and need assistance with drawing mixed tiles in a cross pattern (Herringbone). var canvas = this.__canvas = new fabric.Canvas('canvas' ...

What is the best way to ensure these 2 divs are aligned vertically in the provided html (starting at the same vertical level)?

<div class="container"> <div class="row"> <div class="col-lg-12"> <div class="news-title"> <h3 class="title">NEWS & ARTICLES</h3> ...

HTML Plant with background removed

I have been attempting to create a tree structure similar to the image provided. However, I am encountering difficulty in getting the background stripes to align properly for a specific row. When resizing the browser window, the stripes do not remain fixed ...

Enhance Your HTML Skills: Amplifying Table Display with Images

Recently, I utilized HTML to design a table. The Table Facts : In the first row, I included an appealing image. The second row contains several pieces of content. In continuation, I added a third row. The contents in this row are extensive, resulting i ...

Implementing a Moving Background Image with CSS3 or jQuery

I am facing an issue with a background image that has a file size of 4+ MB in PNG format. My website is a single page website and I want to use this background image, but I'm unsure how to go about it. Is there a way to reduce the size of the image s ...

Image not found in Rotativa PDF document

We have implemented Rotativa to generate and save a PDF version of our web page on the server. Below is the ASP.NET MVC 4 code snippet used for this purpose: var pdfResult = new ActionAsPdf("Index", new { orderId = orderValidated.orderID }) { FileName = ...

Steps to create a hover effect similar to that of a website (increasing grid size on hover)

Looking to create a hover effect for my boxes similar to the one on this website: I've examined the code of the website above and searched extensively for a similar feature without any luck. Could anyone offer assistance with this, please? ...

Can Selenium be executed from a <py-script> within an HTML file?

prefs = webdriver.ChromeOptions() prefs.add_experimental_option("detach", True) driver = webdriver.Chrome(ChromeDriverManager().install(), options=prefs) Following this code, it seems to stop running (It runs fine in a .py file so I believe all ...

Swapping out video files with varying quality using HTML5 and Jquery

Objective: Implementing a feature to change the video being played when a user clicks a button using Jquery. Example website for reference: (click on the "hd" button in the player control) More details: When the page loads, the browser will play the fi ...

Is it possible to stack navbar items in CSS?

I'm facing an issue with my navbar menu items overlapping on top of each other. https://i.sstatic.net/dEEpx.png What could be the reason behind this? Codepen Link: https://codepen.io/ogonzales/pen/mdeNNLB Code Snippet: <nav class="navbar navb ...

How can I conceal the contents of a webpage until the entire page has finished loading before revealing them?

Is there a way to delay displaying my login template until all elements are fully loaded? Currently, when I visit the site, the template appears first followed by fonts and other components. I want to ensure that nothing is shown to the user until the enti ...

Show only the selected option with jQuery's on change event and disable or remove the other options

My goal is to make it so that when a user selects an option from a dropdown menu, the other options are disabled or hidden. For example, if option "1" is selected, options "2", "3", and "4" will be removed: <div class="abc"> <div class="xyz"> ...

How to access the CSS and JS files in the vendor folder using linemanjs

Currently, I am in the process of developing a web application utilizing linemanjs. However, I have encountered an issue where the vendor css and js files are not being referenced correctly when explicitly included. I would appreciate any guidance on what ...

Enable wp_star_rating for display on the front end

My goal is to incorporate the wp_star_rating function into a shortcode for use on the frontend of my WordPress website. To achieve this, I have copied the code from wp-admin/includes/template.php to wp-content/themes/hemingway/functions.php. I have includ ...

Simultaneously scrolling left and fading in with jQuery

I've come across this code that works well in scrolling my divs to the left. However, I'm looking to add a fading effect while they are scrolling. Is there a way to achieve this? $('div#line1').delay(1000).show("slide", { direction: "r ...