Step-by-step guide on setting up a navigation menu with a sidebar similar to the one found on mail

Is there a way to create a navigation menu with a sidebar similar to the one on ? The sidebar should appear when hovering over a navigation link, such as "products", while still allowing visibility and interaction with other links in the navigation. I'm having trouble implementing this functionality because currently, the sidebar covers up the navigation links when it appears.

See an example here.

<html>
  <head>
    <style>
      #menu {
        width: 100%;
        height: 70px;
        border: 1px black solid;
      }

      #submenu {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        border: 1px black solid;
        width: 500px;
        background-color: gray;
        z-index: 600;
        display: none;
      }

      .open {
        z-index: auto;
        display: block !important;
      }

      .link {
        vertical-align: middle;
        display: inline-block;
      }

      .linkOpen {
        z-index: 620;
      }
    </style>
  </head>
  <body>
    <div id="menu">
      <a class="link" id="link" href="/" onmouseover="addStyle()" onmouseleave="removeStyle()">link1</a>
      <div id="submenu">
        <ul>
          <li>123</li>
          <li>456</li>
        </ul>
      </div>
      <a class="link" href="/">link2</a>
      <a class="link" href="/">link3</a>
    </div>
    <script>
      function addStyle() {
        var element = document.getElementById("submenu");
        element.classList.add("open");
        var link = document.getElementById("link");
        link.classList.add("linkOpen");
      }

      function removeStyle() {
        var element = document.getElementById("submenu");
        element.classList.remove("open");
      }
    </script>
  </body>
</html>

Answer №1

To achieve what you're attempting to do, consider utilizing the z-index property along with proper nesting of elements.

For a basic example (without animations and detailed element proportions/placement), check out this link: https://example.com/codepen

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

What is the best way to position sharing buttons slightly to the right?

Looking at the page, it's noticeable that the share buttons are positioned all the way to the left and don't align well with the layout. It looks a bit off. I'm interested in shifting the share buttons slightly to the right so they better m ...

Guide to aligning inline-forms at the center using Bootstrap 4

Check out my HTML: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <script src="https: ...

Bringing app templates and static files into Django templates

I am trying to include my gallery.html and gallery.css files within my base.html. After running the collectstatic and runserver commands, I am unable to locate the gallery.css and html files when inspecting with Chrome Dev Tools. Only the base.html and its ...

Trouble with displaying a CSS background image in Google Chrome on the Three.js birds demo

My website displays a background image in both Safari and Firefox, but for some reason Google Chrome is not showing it. I am unsure why this is happening. Do you have any insights on what I might need to adjust? renderer = new THREE.CanvasRenderer(); ren ...

How come only half of my website is inaccessible when utilizing a sticky navigation menu, and what can be done to remedy this issue?

I've successfully implemented a menu on my website that stays fixed at the top of the page while scrolling. However, there is an issue where I am unable to click on the top 50% of the screen, rendering the website unusable. You can view a test copy of ...

Is there a way to eliminate a div and all its contents from the DOM?

As I work on my web application, I am trying to implement a system where error messages can be returned via ajax upon success or failure. The ajax script is functioning correctly in terms of returning errors or successes. However, my challenge lies in com ...

Is there a way to repurpose a function to work with both ids and classes?

My current code is affecting all elements instead of just the intended one. I've experimented with classes and ids, ruling out those as potential issues. I'm hoping for my JavaScript to target only the selected element, not all of them. Check ou ...

Table of Wordpress posts

There has been a question on how to easily add tables to blog posts without having to use HTML. While some are comfortable inserting the code directly into the blog, others like my friend prefer alternatives that don't involve coding. Is there a simpl ...

What could be causing the no-repeat functionality to fail on these background images, and what steps can be taken to prevent the list text from overlapping with the image?

UPDATE EDIT. There is still an unresolved issue with this problem. Although setting the background to no-repeat fixed the image repetition problem, the list item text still overlaps the background image and there is an extra tick to the left. Please refer ...

Can anyone suggest a solution to troubleshoot this issue with CSS Flexbox and absolute positioning?

I'm currently developing a React application featuring flex container cards (referred to as .FilmCard with movie poster backgrounds) within another flex container with flex-wrap. Each card has an item positioned absolutely (an FontAwesome arrow icon). ...

What is the best way to position an element on the left side of the navbar without having it animated?

Could someone assist me in placing the Life's Good logo on the left side of the nav bar without applying the animation from the "btn" class? Below is a snippet of my code with an example where I want the logo highlighted in Yellow: * { padding:0; m ...

Animated CSS Checkmark Design

How can I create an animated Check-mark using CSS with SVG animation? I attempted the following code but it doesn't seem to be working. Any suggestions? DEMO: https://jsfiddle.net/b7Ln0jns/ CSS: @import "bourbon"; $color--green: #7ac142; $curve: c ...

How can two unique links toggle the visibility of divs with two specific IDs?

I am developing an interactive questionnaire that functions like a 'create your own adventure' story. The questions are shown or hidden depending on the user's responses. Below is the HTML code: <!-- TIER 3 ============================== ...

Limit the text input area in HTML to a fixed size, preventing any text from exceeding the specified boundary

Is there a way to create a fixed line text area that limits the user from typing beyond a certain number of lines and maximum width? My current CSS styling for this is as follows: .area-style { resize: none; width: 324px; height: 200px; m ...

Utilizing Python and Selenium to Locate an Element Based on Text Within a Span Class

My challenge is locating an element without any ID or distinctive identifiers. The HTML code structure resembles the following: <div class="item_select"> <span class="item_selection_number">A </span> </div> <div class="item_ ...

I'm having trouble with Bootstrap 4 where my fixed navbar won't stay separate from my jumbotron

Currently working on a website and utilizing Bootstrap. Looking to keep my fixed navbar distinct from my jumbotron, but struggling to achieve separation between the two. Is there a method to accomplish this without directly modifying the CSS file? Here i ...

Gradually enlarging the size of the font as time progresses

$( "h1" ).hover( function(){ for(var i=0;i<255;i++){ setTimeout(function(){$("#fat").css("font-size", (i + 12) + "pt")},200); } }, function(){$("#fat").delay(200).css("font-size","12pt")} ); My goal is to gradua ...

I'm facing an issue with my owl Carousel not functioning properly in my initial setup. Can anyone help me identify the error?

I've made several attempts but still can't figure out where my error lies. Why doesn't it work for me? It's the "OWL CAROUSEL CUSTOM". I've tried different types of owl carousels and none of them seem to run on my computer. I reall ...

Could not locate the CSS file within the HTML document (404)

I've searched high and low on YouTube but can't seem to find a solution to this problem. Every time I run the code, it gives me an error message saying GET net::ERR_ABORTED 404 (NOT FOUND) <html> <head> <title>itays websit ...

Using single page anchor tags in Next.js to toggle content visibility

The Issue Currently working on a project using Next.js and facing a challenge: needing to hide or replace content based on the selected category without reloading the page or navigating to another route. Furthermore, ensuring that when the page is reloade ...