Developing an Expandable Menu for Easy Navigation

I am looking to create a collapsible master navigation bar that will have another collapsible navigation bar inside. I already have one collapsible navigation bar, but I can't figure out how to make a master navigation bar that contains it. In the code below, I have created a collapsible bar called 'Profile' and I want to add another collapsible bar called 'Navigation' which will contain the 'Profile' navigation bar.

I attempted to modify the CSS as shown below:

.menu {
  border-radius: 8px;
  position: relative;
}

I tried adding: .menu {
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  transition: max-height 0.3s;
  max-height: 0;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <title></title>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
</head>
<style>
  * {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    list-style: none;
    text-decoration: none;
  }
  
  .menu {
    border-radius: 8px;
    position: relative;
  }
  
  .btn-nav {
    display: block;
    padding: 16px 20px;
    background: #333;
    color: white;
    font-size: 2em;
  }
  
  ... (CSS code continues)

My goal is to create a collapsible navigation bar that will include another collapsible navigation bar.

For instance, when clicking on a navigation bar, a second collapsible navigation bar should appear, which can also be collapsed.

Answer №1

If you're looking to create a collapsible menu with some stylish CSS effects, one way is to utilize Bootstrap collapse feature. Here's a snippet of code to get you started:

.menu {
  border-radius: 8px;
  position: relative;
}
* {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  list-style: none;
  text-decoration: none;
}

.menu {
  border-radius: 8px;
  position: relative;
}

.btn-nav {
  display: block;
  padding: 16px 20px;
  background: #333;
  color: white;
  font-size: 2em;
}

.item {
  border-top: 1px solid #2980b9;
  overflow: hidden;
}

.btn {
  display: block;
  padding: 16px 20px;
  background: #3498db;
  color: white;
  position: relative;
}

.btn:before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: #3498db;
  left: 20px;
  bottom: -7px;
  transform: rotate(45deg);
}

.btn i {
  margin-right: 10px;
}

.smenu {
  background: #333;
  overflow: hidden;
  transition: max-height 0.3s;
  max-height: 0;
}

.smenu a {
  display: block;
  padding: 16px 26px;
  color: white;
  font-size: 14px;
  margin: 4px 0;
  position: relative;
}

.smenu a:before {
  content: "";
  position: absolute;
  width: 6px;
  height: 100%;
  background: #3498db;
  left: 0;
  top: 0;
  transition: 0.3s;
  opacity: 0;
}

.smenu a:hover:before {
  opacity: 1;
}

.item:target .smenu {
  max-height: 10em;
}

For the complete tutorial and how-to guide, you can visit https://www.w3schools.com/bootstrap/bootstrap_collapse.asp. Hope this information proves valuable!

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

Streamlined Boilerplate to Kickstart Your Project

Can anyone suggest a well-crafted boilerplate .less file to kickstart a new project? I'm looking for a comprehensive .less file that includes: CSS Resets styles CSS Normalizer styles CSS3 Helpers (box radius, gradients, box shadow, transition) Basic ...

Tips for maintaining the chat scroll position while typing on mobile devices

Check out this example page: https://codesandbox.io/s/summer-flower-uxw47?file=/index.html:4175-4223 The issue at hand is that when accessing the site from a mobile device and tapping on the input field, the keyboard pops up. This causes the text in the m ...

Encountering an unusual hash code when implementing Google Tag Manager in a Next.js project was

I am currently using Next.js and have added Google Tag Manager through a script <script dangerouslySetInnerHTML={{ __html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var ...

ways to conceal list elements using an HTML search box

Is there a way to hide list items from the filter in an HTML search box? For example, I only want the items to show when I click on the search box and then display the item list. Otherwise, I would like the list items to be hidden under normal conditions ...

Tips for overlaying a button on top of an image using CSS

I am currently working on a project where I need to position a button over an image. My reference for this task is the W3schools CSS website, and I have made some modifications to the code provided in the link here: https://www.w3schools.com/css/tryit.asp ...

Append additional information to the end of every .css and .jpg file

My goal is to append ?v= + Math.floor(Math.random()); at the end of every .css and .jpg file. I am still a beginner with JQuery and here is what I have managed to come up with so far. $(document).ready(function(){ $(something).each(function( index ) ...

retrieve the Jquery progress bar's current value

Having trouble determining the value of the progress bar in order to increase it by a percentage with each step. No matter what I attempt, I keep getting errors such as 'undefined' or 'method cannot be called before object instantiation.&apo ...

Customizing Body Color in CKEditor for Dynamic Designs

I am facing an issue with CKEditor that I am hoping to find a solution for. My scenario involves using a jQuery color picker to set the background color of a DIV element, which is then edited by the user in CKEditor. However, I have observed that it is not ...

Experiencing difficulty with the toggle menu on an HTML/CSS website. Unable to access the menu when hovering over the hamburger icon on the right side

I am experiencing an issue with the toggle button in the menu when the screen size is max-width = 1200px. Specifically, when I toggle the button, nothing appears. Can someone please assist me? I have included Bootstrap 4.3 in my HTML script. The menu that ...

Tips for creating a consistently positioned div element, regardless of the screen size

Having trouble positioning two bars with green or blue filling in the bottom right corner? They keep moving around and not staying in place regardless of screen size. Check out how they are off-screen here Below is the CSS-Styling + HTML code: .eleme ...

Whenever I add Bootstrap to my Vue3 Class Component Typescript project, I notice a significant slowdown in the compilation and build

I've noticed that my application takes much longer to build with vue-cli (whether it's a production build or just running the development server). I'm importing bootstrap in a SCSS file where I customize some rules, and this file is then im ...

Use JavaScript to generate an HTML element that has an attribute mirroring its text content

Trying to figure out how to create an HTML element similar to this: <option value="Replaced">by this</option> For example: <option value="ThisIsTest">ThisIsTest</option> UPDATE Using jQuery, I need to achieve something like thi ...

Can the CSS property "float: none;" interfere with the Javascript function "ng-click"?

This particular issue is quite strange. Setting "float: none;" appears to be preventing the execution of Javascript (ng-click). new.html.haml (where "float: none;" is located) .container{ng: {controller: 'sample_1_controller'}} %nav.bread.m ...

How can I transform HTML into a PDF file using PHP?

I've come across numerous posts discussing this issue. However, I'm in need of assistance setting up the script to run on my localhost. Despite trying various solutions and installing imagemagick, ghostscript, activeperl, and more, I still haven ...

Center align your animations without using the text-align property

I'm in the process of refining this custom animation to make it smoother. Check out the live animation here. The issue I'm encountering is that during the transition when the city name rotates up and replaces the old one, the text-align center ...

Nested Property Binding in CallByName

I am looking to utilize CallByName in VBA to extract specific data from various webpages with differing html structures. In my scenario, I need to reference multiple parent nodes to access an element with or tags. Here is an example of the code: The eleme ...

The functionality of one button triggering the opening of two dropdown menus simultaneously is being successfully implemented

My issue is that I have created two different dropdowns, but they both open the same dropdown menu. Here is my code; <div class="d-flex"> <button class="btn btn-icon btn-group-nav shadow-sm btn-secondary dropdown-toggle" type="butto ...

transfer the output from the second selection to the adjacent div

I am utilizing a library called select2 specifically for single choice scenarios. My goal is to transfer the selected option to a different div once it has been chosen. Here is the code I have so far: https://jsfiddle.net/hxe7wr65/ Is there a way to ach ...

Display a petite popup above the selected text within the Code Mirror editor

I have been utilizing the following code snippet to highlight text segments in Codemirror, a renowned code editor and syntax highlighter that can be downloaded from this link. Despite referring to the documentation, I am still unable to grasp how this fun ...

Arranging inline-flex elements within a div container

I have been struggling to position two elements side by side within a single div, where the second element should be on the right side. <div className={classes.container}> <div className={classes.first}> First </div> <d ...