Enhanced navigation with Bootstrap 4 collapsible nav group

I am currently designing a documentation website layout with the Table of Contents displayed in a right-hand column and the content presented in the left-hand column. The TOC includes various groups of code snippets similar to the example below. Is there a method to enable collapsing and expanding of the submenu navigation by clicking on the anchor tag? This way, all submenus would be collapsed upon page load, allowing users to expand and collapse them as needed.

Orgbrat

.doc-sub-menu {
  list-style: none;
  padding-left: 0;
}

.doc-sub-menu .nav-link {
  margin-bottom: 10px;
  font-size: 12px;
  display: block;
  color: #616670;
  padding: 0;
  padding-left: 34px;
  background: none;
}

.doc-sub-menu .nav-link:first-child {
  padding-top: 5px;
}

.doc-sub-menu .nav-link:hover {
  color: #494d55;
  text-decoration: none;
  background: none;
}

.doc-sub-menu .nav-link:focus {
  background: none;
}

.doc-sub-menu .nav-link.active {
  background: none;
  color: #40babd;
}

.body-blue .doc-sub-menu .nav-link.active {
  color: #58bbee;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<a class="nav-link text-dark" asp-area="" asp-page="/UserGuide/Items">Adding and Managing Items</a>
<nav class="doc-sub-menu nav flex-column">
  <a class="nav-link scrollto" href="#html">Medications</a>
  <a class="nav-link scrollto" href="#css">Blood Sugars</a>
  <a class="nav-link scrollto" href="#sass">Pharmacies</a>
  <a class="nav-link scrollto" href="#less">Physicians</a>
  <a class="nav-link scrollto" href="#javascript">Family Members</a>
  <a class="nav-link scrollto" href="#python">Appointments</a>
  <a class="nav-link scrollto" href="#php">Medical Records</a>
</nav>
<!--//nav-->

Answer №1

A great feature of Bootstrap 4 is the ability to use the default class "collapse" and data-toggle tag. You can easily implement this by following the snippet below:

.doc-sub-menu {
            list-style: none;
            padding-left: 0;
          }

          .doc-sub-menu .nav-link {
            margin-bottom: 10px;
            font-size: 12px;
            display: block;
            color: #616670;
            padding: 0;
            padding-left: 34px;
            background: none;
            cursor: pointer;
          }

          .doc-sub-menu .nav-link:first-child {
            padding-top: 5px;
          }

          .doc-sub-menu .nav-link:hover {
            color: #494d55;
            text-decoration: none;
            background: none;
          }

          .doc-sub-menu .nav-link:focus {
            background: none;
          }

          .doc-sub-menu .nav-link.active {
            background: none;
            color: #40babd;
          }

          .body-blue .doc-sub-menu .nav-link.active {
            color: #58bbee;
          }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

<a class="nav-link text-dark" asp-area="" asp-page="/UserGuide/Items" data-toggle="collapse" data-target="#slide-submenu">Adding and Managing Items</a>
      <nav id="slide-submenu" class="doc-sub-menu nav flex-column collapse">
        <p>
          <a class="nav-link scrollto" href="#html">Medications</a>
          <a class="nav-link scrollto" href="#css">Blood Sugars</a>
          <a class="nav-link scrollto" href="#sass">Pharmacies</a>
          <a class="nav-link scrollto" href="#less">Physicians</a>
          <a class="nav-link scrollto" href="#javascript">Family Members</a>
          <a class="nav-link scrollto" href="#python">Appointments</a>
          <a class="nav-link scrollto" href="#php">Medical Records</a>
        </p>
      </nav>

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

Issue with Bootstrap dropdown not extending as expected

My issue lies with the functionality of my Bootstrap dropdown. When I scroll down, I can view the dropdown results within the designated area next to the label, however they are not expanding as expected. ...

Tips for accessing the height property of an image

Is there a way to determine if an image lacks the height style property? Exploring CSS in HTML <img id="image" src="images/sports/sports9.png" style="width:100px"> Using jQuery if($('#image').css('height') == 0) { var ima ...

Changing the color of child divs on rollover in a parent div

When I hover over my parent div containing 3 child divs, only parts of the child divs change color. How do I make all the child divs change color when part mouse is hovered over them? Any help would be appreciated. Thanks! This is the code I have attempte ...

When viewing my website on larger screens, the CSS and Bootstrap 5 styling ensure a responsive design. However

I've been working on creating a webpage using Bootstrap 5, and I've managed to make it responsive for mobile devices using @media queries. However, I'm facing an issue where some of the divs, sections, and rows are not aligning properly when ...

Tips for sending images as properties in an array of objects in React

I've been experimenting with various methods to display a background image underneath the "box" in styled components. How can I pass an image as a prop into the background image of the box with the image stored in the array of objects? I'm unsure ...

Is there a way to display the button solely when the cursor is hovering over the color?

When I hover over a particular color, I want the button to show up. However, instead of displaying the button only for that color, it appears for all the colors of the product. Also, the placement of the button on the left side means that if I try to hover ...

Tips for updating the border color of a div upon clicking it

Currently working on a project using react/typescript and facing an issue with changing the border color and width of a div upon clicking it: <div className="showroom-card " onClick={() => setSelection({ showroom: &ap ...

Guidelines for aligning a form in the middle of the screen (positioned between the navigation bar and footer

Before asking this question, I made sure it's not a duplicate by researching previous similar issues with no success. I'm currently utilizing Bootstrap 4. You can view my app at (I'm unable to post the CSS and HTML of my React app due to S ...

Append the class to the div element

Hey there, I'm dealing with a div tag that looks like this: <div id = "product-tabs" class="gen-tabs gen-tabs--style1"> Now, I have to add 'accor' to the end of the class section, so it would look like this: gen-tabs gen-tabs--style ...

I'm having trouble aligning my 'a' element that I'm trying to use as the close button for my modal component. Why is it not centering?

I have successfully created a styled "a" element that functions as a close button for a modal, redirecting you to the home page when clicked. However, I am facing an issue with vertically centering the "X" within the button. Enclosing it in a "button" elem ...

What is the best way to structure Vue.js components for optimal organization?

Imagine having an index page called index.vue consisting of various components like this: index.vue <template> <div> <component-1 /> <section class="section-1"> <div class="container section-container"> <com ...

What is the best way to conceal a specific column within an HTML table through CSS styling?

My HTML table looks like this: <table class="report"> <tbody> <tr> <td >col1</td> <td >col2</td> <td>col3</td> <td >&nbsp;</td> <td ...

Preventing clicking on minute cell

check out the fiddle I am working with an HTML table that includes a textbox and a button. I need to enable cell selection by dragging on the cell. When the button is clicked, I want to retrieve the value from the textbox and display it in a span tag with ...

Setting a specific time for a div element with opacity: A step-by-step guide

Is there a way to adjust the timing for the appearance of the add-to-cart when hovering over the product-list-item? Currently, it appears when I hover over the item and disappears when I move my mouse away. .product-list-item { position: relative; w ...

Customizing your Laravel list

I am experiencing difficulties with the edit module in my master-detail listing. The master table is groups, and the detail table is hours. The issue I am facing is that I can only modify the data of the first row. This could be because the controls in the ...

Initial two slides of the Bootstrap carousel appear clunky in full screen mode

After researching on various platforms, including Stack Overflow, I came across a similar question that I am facing now. Unfortunately, none of the solutions provided have worked for me so far. I apologize if this is repetitive, but I can't seem to fi ...

Reasons behind the lack of proper styling in my p-calendar from PrimeNG

Currently deep diving into Angular for a project and I decided to incorporate the <p-calendar> component from primeng. After installing the necessary packages, the versions were: "primeicons": "^2.0.0", "primeng": "^5.2.7", Initially everything was ...

Unique version: "Each tab uses a unique pagination system that ultimately leads to the same content

Apologies for the novice question. Currently, I have: • a webpage with different tabs, each containing a pagination The issue arises when clicking on a page in one pagination, it redirects to: • a different tab For example, clicking on page 2 in t ...

Having trouble with flickering in rotating card animation in Bootstrap using CSS?

Recently, I worked on a bootstrap website where I implemented a unique feature – a card that flips to show its backside upon hover. You can check out the live website here: Live Site Here's the code snippet for the section with the flipping card: ...

Exploring the versatility of Angular by creating various flex layouts with Angular Material cards

I'm struggling to implement the design shown below using cards and a flex layout in a responsive way. I've tried working on it using StackBlitz but haven't been able to get it right - the margin and layout get messed up on different screens. ...