1

I designed some CSS rules for a responsive navigation menu which allows me to add sub-menus, but each sub-menu requires the creation of new CSS selectors. I want to style the menu and submenus once so that a beginner user does not need to add any new CSS selectors in order to create nested submenus.

I want the submenus to open as shown in this link (watch the first 34 seconds of the video).

const MenuButton = document.querySelector(".nav-menu-button");
const Navigation = document.querySelector(".nav");
let MenuOpen = false;
MenuButton.addEventListener("click", () => {
  switch (!MenuOpen) {
    case true:
      MenuButton.classList.add("open");
      Navigation.setAttribute("data-visible", "true")
      MenuOpen = true;
      break;
    default:
      MenuButton.classList.remove("open");
      Navigation.setAttribute("data-visible", "false")
      MenuOpen = false;
      break;
  }
});
@font-face {
  font-family: "Roboto";
  font-style: normal;
  src: url("../Fonts/Roboto.ttf") format("truetype");
}

* {
  font-family: "Roboto";
  font-size: 20px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  direction: rtl;
}

.logo {
  z-index: 10;
  position: relative;
}

.header {
  float: center;
  background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
  border-radius: 10px;
  box-shadow: 1px 2px 4px #000000;
  color: white;
  width: 100%;
  height: 100px;
  padding-left: 0px;
  padding-right: 10px;
  padding-top: 40px;
  text-align: right;
  text-shadow: 0px 2px 2px #000000;
}

.nav {
  list-style: none;
  display: flex;
  gap: 24px;
}

.nav li a {
  text-decoration: none;
  font-size: 28px;
  color: #f3b238;
  display: inline-block;
  width: 100%;
  position: relative;
}

.nav li a:hover {
  color: #fff;
}

.nav li a::after {
  content: "";
  width: 0%;
  height: 4px;
  background-color: #fff;
  position: absolute;
  left: 0px;
  bottom: -5px;
  border-radius: 5px;
  transition: all 0.7s ease;
}

.nav li a:hover::after {
  width: 100%;
}

@media (max-width: 769px) {
  .nav {
    position: fixed;
    inset: 0;
    background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
    flex-direction: column;
    align-items: center;
    /*padding-top: 150px;*/
    padding-top: 70px;
    transform: translateX(100%);
    transition: all 0.7s ease;
  }

  .nav[data-visible=true] {
    transform: translateX(0%);
  }

  .nav-menu-button {
    position: absolute;
    display: flex;
    z-index: 10;
    justify-content: center;
    align-items: center;
    height: 80px;
    width: 80px;
    right: -10px;
    top: -10px;
    cursor: pointer;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line {
    width: 50px;
    height: 6px;
    background-color: #d0fd66;
    border-radius: 5px;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line::before,
  .nav-menu-line::after {
    content: "";
    position: absolute;
    width: 50px;
    height: 6px;
    background-color: #d0fd66;
    border-radius: 5px;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line::before {
    transform: translateY(-16px);
  }

  .nav-menu-line::after {
    transform: translateY(16px);
  }

  .nav-menu-button.open .nav-menu-line {
    transform: translateX(-50px);
    background: transparent;
  }

  .nav-menu-button.open .nav-menu-line::before {
    transform: rotate(45deg) translate(35px, -35px);
  }

  .nav-menu-button.open .nav-menu-line::after {
    transform: rotate(-45deg) translate(35px, 35px);
  }
}
<div class="logo" role="img">
  <img src="Images/Logo.png" height="100" style="width:auto; float:left;" />
</div>
<header class="header">
  <div class="nav-menu-button">
    <div class="nav-menu-line"></div>
  </div>
  <nav class="nav" data-visible="false" role="navigation">
    <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Goods</a>
    </li>
  </nav>
</header>
R_J
  • 52
  • 12
  • I see that you linked to a video for an example, have you tried the code mentioned in the video? – imvain2 Jul 10 '23 at 21:56
  • My `CSS` code is a combination of the above link and another link; therefore, I'm having trouble with this part. – R_J Jul 10 '23 at 22:24
  • I don't quite understand what you mean by "each sub-menu requires the creation of new CSS selectors. I want to style the menu and sub-menus once so that a beginner user does not need to add any new CSS selectors". Please explain and include a reproducible example. I'm not going to watch a 46-minute video just to see if it explains what you failed to explain. – Tim R Jul 11 '23 at 04:24
  • I want to style the menu and sub-menus once so that a beginner user does not need to add any new selectors in `SASS` to add submenus in `HTML`. – R_J Jul 11 '23 at 09:04
  • I want to style the menu and sub-menus one time forever. – R_J Jul 11 '23 at 09:07
  • I don't see any submenus in your code snippet, maybe you could add one first? – Damzaky Jul 11 '23 at 12:22
  • If I add submenus, it doesn't look the way I want. – R_J Jul 11 '23 at 18:57
  • 2
    The bounty attracted two [ChatGPT](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned) plagiarisers. – Peter Mortensen Jul 12 '23 at 14:45
  • I agree with you – R_J Jul 12 '23 at 16:11
  • Can anyone give a complete answer to this question? – R_J Jul 15 '23 at 16:30

4 Answers4

1

I think this is kinda what are you looking for.

const MenuButton = document.querySelector(".nav-menu-button");
const Navigation = document.querySelector(".nav");

let MenuOpen = false;

MenuButton.addEventListener("click", () => {
  switch (!MenuOpen) {
    case true:
      MenuButton.classList.add("open");
      Navigation.setAttribute("data-visible", "true")
      MenuOpen = true;
      break;
    default:
      MenuButton.classList.remove("open");
      Navigation.setAttribute("data-visible", "false")
      MenuOpen = false;
      break;
  }
});

$('.dropdown-menu a.dropdown-toggle').on('click', function(e) {
  if (!$(this).next().hasClass('show')) {
    $(this).parents('.dropdown-menu').first().find('.show').removeClass('show');
  }
  var $subMenu = $(this).next('.dropdown-menu');
  $subMenu.toggleClass('show');
  reposition();

  $(this).parents('li.dd1.dropdown.show').on('hidden.bs.dropdown', function(e) {
    $('.dropdown-submenu .show').removeClass('show');
    reposition();
  });


  return false;
});

let reposition=()=>{
  let dml=document.querySelector('#navbarDropdownMenuLink'),
      dd1=document.querySelector('.dropdown.dd1'),
      nvi=document.querySelectorAll('nav.nav>li:not(.dropdown)');
  dd1.style.transform='translate(0px,0px)';
  let wdt=0;
  for(let el of nvi){
    let rect=el.getBoundingClientRect();
    wdt+=rect.width+10;
  }
  let rect=dml.getBoundingClientRect();
  dd1.style.transform=`translate(${window.innerWidth-(rect.left+rect.width+wdt+10)}px,0px)`
}

let func=()=>{
  $('<br/>').insertAfter($('#navbarDropdownMenuLink'));
  reposition();
}

if(document.readyState=='complete')func();
$(document).ready(func);

window.addEventListener('resize',reposition);
* {
  font-size: 20px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  direction: rtl;
}

.logo {
  z-index: 10;
  position: relative;
}

.header {
  background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
  border-radius: 10px;
  box-shadow: 1px 2px 4px #000000;
  color: white;
  width: 100%;
  height: auto;
  padding-left: 0px;
  padding-right: 10px;
  padding-top: 40px;
  padding-bottom: 20px;
  text-align: right;
  text-shadow: 0px 2px 2px #000000;
}

.nav {
  list-style: none;
  display: flex;
  gap:10px;
}

.dropdown-menu{
  background: #00000000 !important;
  border-width:0 !important;
  position:unset !important;
  transform:none !important; /* translate(32px, 0) */
  margin: inherit !important;
  margin-top: 10px !important;
  padding:0;
  margin-left: 0;
  width: min-content;
  min-width:0 !important;
}

.dropdown-submenu>.dropdown-menu.show{
  width:100% !important;
}

.dropdown-item{
  padding-left:0 !important;
  padding-right:0 !important;
  width:fit-content !important;
  float: left;
}

.dropdown-item:hover{
  background-color:#00000000 !important;
}

.dropdown-item:focus{
  background-color:#00000000 !important;
  color:#fff !important;
}

.dropdown-toggle::after{
  border-width:0 !important;
  background-image:none;
  margin:0 !important;
}

.dropdown-toggle{
  float:left;
}

.nav li a {
  text-decoration: none;
  font-size: 28px;
  color: #f3b238;
  display: block;
  position: relative;
}

.nav li a:hover {
  color: #fff;
}

.nav li a::after {
  content: "";
  width: 0%;
  height: 4px;
  background-color: #fff;
  position: absolute;
  left: 0px;
  bottom: -5px;
  border-radius: 5px;
  transition: all 0.7s ease;
}

.nav li a:hover::after {
  width: 100%;
}

@media (max-width: 769px) {
  .nav {
    inset:0;
    position: fixed;
    background: linear-gradient(to top, #9472ff 2%, #3d00ff 98%) center/100%;
    flex-direction: column;
    align-items: center;
    /*padding-top: 150px;*/
    padding-top: 70px;
    transform: translateX(100%);
    transition: all 0.7s ease;
  }

  .nav[data-visible=true] {
    transform: translateX(0%);
  }

  .nav-menu-button {
    position: absolute;
    display: flex;
    z-index: 10;
    justify-content: center;
    align-items: center;
    height: 80px;
    width: 80px;
    right: -10px;
    top: -10px;
    cursor: pointer;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line {
    width: 50px;
    height: 6px;
    background-color: #d0fd66;
    border-radius: 5px;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line::before,
  .nav-menu-line::after {
    content: "";
    position: absolute;
    width: 50px;
    height: 6px;
    background-color: #d0fd66;
    border-radius: 5px;
    transition: all 0.7s ease-in-out;
  }

  .nav-menu-line::before {
    transform: translateY(-16px);
  }

  .nav-menu-line::after {
    transform: translateY(16px);
  }

  .nav-menu-button.open .nav-menu-line {
    transform: translateX(-50px);
    background: transparent;
  }

  .nav-menu-button.open .nav-menu-line::before {
    transform: rotate(45deg) translate(35px, -35px);
  }

  .nav-menu-button.open .nav-menu-line::after {
    transform: rotate(-45deg) translate(35px, 35px);
  }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" crossorigin="anonymous"></script>

<div class="logo" role="img">
  <img src="Images/Logo.png" height="100" style="width:auto; float:left;" />
</div>
<header class="header">
  <div class="nav-menu-button">
    <div class="nav-menu-line"></div>
  </div>
  <nav class="nav" data-visible="false" role="navigation">
    <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Goods</a>
    </li>
    <li class="dropdown dd1">
        <a class="dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-expanded="false">
          Dropdown link
        </a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <li><a class="dropdown-item" href="#">Action</a></li>
          <li><a class="dropdown-item" href="#">Another action</a></li>
          <li class="dropdown-submenu">
            <a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Submenu action</a></li>
              <li><a class="dropdown-item" href="#">Another submenu action</a></li>


              <li class="dropdown-submenu">
                <a class="dropdown-item dropdown-toggle" href="#">Subsubmenu</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                  <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                </ul>
              </li>
              <li class="dropdown-submenu">
                <a class="dropdown-item dropdown-toggle" href="#">Second subsubmenu</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                  <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                </ul>
              </li>



            </ul>
          </li>
        </ul>
      </li>
  </nav>
</header>
<div style="height:1000px"></div>

If you need to have everything offline, download files from three links provided at start of HTML and replace urls.

MfyDev
  • 439
  • 1
  • 12
  • @R_J what do you mean by "horizontal direction"? Do you want the menus to open inline in menu istead of popup-style? – MfyDev Jul 13 '23 at 18:52
  • Thank you for your response. Your code allows for the insertion of an unlimited number of submenus, which is very close to what I want. However, the structure of the submenus should have a horizontal direction once it has opened. Please edit it to get the bounty. – R_J Jul 13 '23 at 18:54
  • 1
    @R_J Okay. I'll try my best. – MfyDev Jul 13 '23 at 18:57
  • What I mean is that the layout of the submenus should tilt somewhat to the left or right when they submenus are opened, depending on whether they are to the right or left. – R_J Jul 13 '23 at 20:02
  • Also, all CSS styles and JS code must be local (not linked to other websites). – R_J Jul 13 '23 at 20:48
  • @R_J Edit done. – MfyDev Jul 14 '23 at 18:42
  • As a result of the `Snippet` editor, I didn't notice the right changes. I want the submenus to open as shown in [this link](https://www.youtube.com/watch?v=wlCPOwBr7no) (watch the first 34 seconds of the video). – R_J Jul 15 '23 at 00:28
  • @R_J Why do you want from me to do something by following a tutorial? If you've found a [tutorual](https://www.youtube.com/watch?v=wlCPOwBr7no) already, try to change the code as tutorial says if it suits your needs. And I've already made the multi-level menu system as you asked in the [question](https://stackoverflow.com/questions/76643482/how-can-a-nested-responsive-navigation-menu-be-described-by-css-rules-so-that-a). – MfyDev Jul 15 '23 at 06:30
  • I had previously included this instruction in my question, but one of the moderators erased it after modifying it. Because my code is a compilation of numerous guides, I was unable to accomplish everything that I desired. – R_J Jul 15 '23 at 10:19
1

CSS is designed to happily cascade down a repeating pattern because elements in default (static) positioning are positioned relative to their parents. However you have to decide how you want it to be designed and how it should appear on large screens and mobile over a range of menu depths.

For instance if you want the color to change based on the menu depth you will need to use javascript and you will need to define an algorithm to determine the color. But if you just want something like submenus to be indented relative to their parent, it is easy.

For example each additional sub-menu can have an additional margin/indent relative to the parent.

Or you can use javascript to detect and decorate your various sub-menus with additional classes based on the depth.

You can use .sub-menu > li > .sub-menu to target non-top-level .sub-menus. Or you can just style all .sub-menu and override the top level one if needed (depends on your navbar/menu design). But in any case as a .sub-menu is positioned relative to its parent element in static layouts, just setting a left margin or padding will give incremental indentation down the menu tree.

User Experience Issues

For unlimited sub-menus you are likely to run into user-experience issues with pure css because the menus may eventually start going off the side of the screen so you may need to start using javascript to determine which direction you want a sub-menu to open.

You also need to think about the design and usability between large desktop screen and mobile. Imagine a hamburger menu with unlimited indent...quickly takes over the whole screen with deep menus. On the other hand without indent how does a user visually identify which part of the menu tree they are in?

There are other design paradigms like a menu "slider" with breadcrumbs to allow a user to navigate up and down a menu tree without having to visually see the entire tree at once (breadcrumb shows where they are in the tree, menu heading for current sub-menu and menu contents as a list). This definitely requires javascript for a nice user experience.

But that is getting off topic.

Example

Here is a quick example how you can have unlimited submenus. I didn't make it pretty but you can see all I have done is:

  • style
    • the top level li to be your main nav links (e.g. in a nav bar)
    • and first-level sub-menu to be positioned absolute below their links.

Further submenus just expand in place and due to default browser styles have a nested indent.

I didn't make it pretty.

The javascript is minimal and just handles toggling the classes to open and close menus. You would probably want something more sophisticated (e.g. close menus if the user clicks outside nav or on a different link/sub-menu).

This example is just about illustrating the css.

If you prefer pug/scss see the original codepen version of the below snippet.

var subMenus = Array.from(document.querySelectorAll('.sub-menu')),
    openClass = 'open';

subMenus.forEach(function (menu) {
    var menuLink = menu.previousElementSibling;
    if (!menuLink) {
        return console.error('sub-menu missing link', menu);
    }
    menuLink.addEventListener('click', function () {
       if (menu.classList.contains(openClass)) 
           menu.classList.remove(openClass);
        else
            menu.classList.add(openClass);
    });
});
@charset "UTF-8";
ul.sub-menu {
  display: none;
}
ul.sub-menu.open {
  display: inline-block;
}

.nav-list li > a:after {
  content: "▼";
}
.nav-list li > a:last-child:after {
  content: "";
}

.nav-list > li {
  display: inline-block;
  position: relative;
  margin-right: 2em;
}
.nav-list > li:last-child {
  margin-right: 0;
}
.nav-list > li > .sub-menu {
  position: absolute;
  top: 100%;
  left: 0;
}

.nav-list .sub-menu {
  background-color: pink;
}
<nav>
  <ul class="nav-list">
    <li><a href="#">link1</a></li>
    <li><a href="#">link2 (has submenu)</a>
      <ul class="sub-menu">
        <li><a href="#">link2.a</a></li>
        <li><a href="#">link2.b (has submenu)</a>
          <ul class="sub-menu">
            <li><a href="#">link2.b.a</a></li>
            <li><a href="#">link2.b.b (has submenu)</a>
              <ul class="sub-menu">
                <li><a href="#">link2.b.b.a</a></li>
                <li><a href="#">link2.b.b.b</a></li>
              </ul>
            </li>
            <li><a href="#">link2.b.c </a></li>
          </ul>
        </li>
        <li><a href="#">link2.c</a></li>
      </ul>
    </li>
    <li><a href="#">link3</a></li>
  </ul>
</nav>
mattpr
  • 2,504
  • 19
  • 17
1

I reduced the code into this snippet. The styles are simpler but the JS logic is what you're looking for. After watching the video, it didn't seem like my original post about using complex CSS selectors like .nav ul.sub-menu will accomplish an arbitrarily deep submenu structure. This could be solved discretely if we know the exact number of menus and submenus. I say 'discretely' because we can just create unique ids for each submenu, along with a handler function, and then we just need to add or remove CSS classes for the display property. That's the easy way and it works if your menu is a rigid size that doesn't change and if you don't care about having lots of declarative code that may break if something small gets changed.

But if you want to arbitrarily add or remove submenus on the go, and not have to touch any other code besides HTML, then we can do this programmatically or dynamically.

The CSS you need to add is relatively small:

.sub-menu {
  display: none;
}

.sub-menu[data-visible="true"] {
  display: block;
}

We need to define a rigid structure of HTML that we will add or remove. For my example a submenu element is defined below, so just add or remove as many of these:

<li>
  <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
  <ul class="sub-menu">
    <li>
      <a href="#" >Sub-Submenu Generic</a>
    </li>
  </ul>
</li>

There are probably other ways to do the handler functions, but I made use of event.target.nextElementSibling to toggle submenus. toggleSpecificSubmenu is what get called when a menu or submenu item is clicked, no need more multiple handlers for each item.

function toggleSpecificSubmenu(event) {
  event.stopPropagation();
  const subMenu = event.target.nextElementSibling;
  if (subMenu) {
    toggleSubMenu(subMenu);
  }
}

function closeAllChildSubmenus(subMenu) {
  const childSubmenus = subMenu.querySelectorAll(".sub-menu");
  childSubmenus.forEach(child => {
    child.setAttribute("data-visible", "false");
    closeAllChildSubmenus(child);
  });
}

function closeAllSubmenusExcept(exceptSubMenu) {
  const parentMenu = exceptSubMenu.parentElement.parentElement;
  const childSubmenus = parentMenu.querySelectorAll(".sub-menu");
  childSubmenus.forEach(subMenu => {
    if (subMenu !== exceptSubMenu) {
      subMenu.setAttribute("data-visible", "false");
      closeAllChildSubmenus(subMenu);
    }
  });
}

function toggleSubMenu(subMenu) {
  const isVisible = subMenu.getAttribute("data-visible") === "true";
  if (isVisible) {
    subMenu.setAttribute("data-visible", "false");
    const childSubmenus = subMenu.querySelectorAll(".sub-menu");
    childSubmenus.forEach(child => {
      child.setAttribute("data-visible", "false");
    });
  } else {
    subMenu.setAttribute("data-visible", "true");
  }
}
.sub-menu {
  display: none;
}

.sub-menu[data-visible="true"] {
  display: block;
}
    <nav class="nav" data-visible="false" role="navigation">

      <li>
        <a id="home" href="#">Home</a>
        <ul class="sub-menu">
          <li>
            <a href="#">Submenu Generic</a>
          </li>
        </ul>
      </li>

      <li>
        <a id="goods" href="#" onclick="toggleSpecificSubmenu(event)">Goods</a>
        <ul class="sub-menu">

          <li>
            <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
            <ul class="sub-menu">
              <li>
                <a href="#" >Sub-Submenu Generic</a>
              </li>
            </ul>
          </li>

          <li>
            <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
            <ul class="sub-menu">
              <li>
                <a href="#" >Sub-Submenu Generic</a>
              </li>

              <li>
                <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
                <ul class="sub-menu">
                  <li>
                    <a href="#" >Sub-Submenu Generic</a>
                  </li>
                </ul>
              </li>

              <li>
                <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
                <ul class="sub-menu">
                  <li>
                    <a href="#" >Sub-Submenu Generic</a>
                  </li>
                </ul>
              </li>

              <li>
                <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
                <ul class="sub-menu">
                  <li>
                    <a href="#" >Sub-Submenu Generic</a>
                  </li>

                  <li>
                    <a href="#" onclick="toggleSpecificSubmenu(event)">Submenu Generic</a>
                    <ul class="sub-menu">
                      <li>
                        <a href="#" >Sub-Submenu Generic</a>
                      </li>
                    </ul>
                  </li>

                </ul>
              </li>

            </ul>
          </li>

        </ul>
      </li>

    </nav>
hygtfrde
  • 130
  • 3
  • Thank you for your response. I want the submenus to open as shown in this [link](https://www.youtube.com/watch?v=wlCPOwBr7no) (watch the first 34 seconds of the video). – R_J Jul 18 '23 at 14:14
  • @R_J Looked at the video example and reworked the JavaScript, the styles are bare bones but menu and submenu logic works – hygtfrde Jul 19 '23 at 05:52
0

Instead of using a flat list for the navigation, nest the submenus within the parent list items using the <ul> and <li> tags.

<nav class="nav" data-visible="false" role="navigation">
  <li>
    <a href="#">Home</a>
  </li>
  <li>
    <a href="#">Goods</a>
    <ul class="submenu">
      <li><a href="#">Submenu 1</a></li>
      <li><a href="#">Submenu 2</a></li>
      <!-- Add more submenus as needed -->
    </ul>
  </li>
</nav>

Then Update CSS Styles:

/* Styles for the nested submenus */
.nav li ul {
  list-style: none;
  display: none; /* Hide nested submenus by default */
}

.nav li:hover > ul {
  display: block; /* Show nested submenus on hover */
}

/* Add additional styling for the nested submenus as needed */
.nav li ul li {
  /* Styles for the nested submenu items */
}

/* Adjust the positioning of nested submenus if needed */
.nav li ul {
  /* tyles for submenu positioning */
}
Wakil Ahmed
  • 1,053
  • 1
  • 8
  • 16