Angular 6 and Bootstrap 4 Collaborate for a Dynamic Multi-Level NavBar

(UPDATE: Issue Resolved - I discovered that I needed to include the JavaScript within $(document).ready(function()), which was previously missing. The example below worked perfectly for me.)

I am attempting to implement a Multi-Level Navbar with Angular 6 & Bootstrap 4.

How can I expand and collapse sub-menus on click or hover? My goal is for the menu to expand towards the right...

For instance, I came across a solution on this webpage - but I'm unsure about how to integrate Javascript into an Angular component. https://codepen.io/surjithctly/pen/PJqKzQ

Here are details of my version:

+-- [email protected]

+-- [email protected]

+-- [email protected]

Below is my Navbar Code:

<nav class="navbar navbar-expand-lg navbar-dark">
    <a class="navbar-brand" href="#" style="color: red;">      
      My NAVBAR
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
        </li>        
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownHI" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  Menu
                </a>
                <ul class="dropdown-menu" aria-labelledby="navbarDropdownHI">
                    <li><a class="dropdown-item" href="#">Action</a></li>
                  <li class="nav-item dropdown"><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>
                    </ul>
                  </li>                
                  <li class="dropdown-divider"></li>
                  <li><a class="dropdown-item" href="#">View All</a></li>
                </ul>
              </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Disabled</a>
        </li>
      </ul>     
    </div>
  </nav>

Answer №1

To enhance your design, you should incorporate custom styles in addition to the provided HTML code

.custom-design {
  position: relative;
}

.custom-design>.design-block {
  top: 0;
  left: 100%;
  margin-top: -6px;
  margin-left: -1px;
  -webkit-border-radius: 0 6px 6px 6px;
  -moz-border-radius: 0 6px 6px;
  border-radius: 0 6px 6px 6px;
}

.custom-design:hover>.design-block {
  display: block;
}

.custom-design>a:after {
  display: block;
  content: " ";
  float: right;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  border-width: 5px 0 5px 5px;
  border-left-color: #ccc;
  margin-top: 5px;
  margin-right: -10px;
}

.custom-design:hover>a:after {
  border-left-color: #fff;
}

.custom-design.pull-left {
  float: none;
}

.custom-design.pull-left>.design-block {
  left: -100%;
  margin-left: 10px;
  -webkit-border-radius: 6px 0 6px 6px;
  -moz-border-radius: 6px 0 6px 6px;
  border-radius: 6px 0 6px 6px;
}
<div class="container">
  <div class="row">
    <div class="dropdown">
      <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  Dropdown
        </button>
      <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
        <li class="dropdown-item"><a href="#">Some action</a></li>
        <li class="dropdown-item"><a href="#">Some other action</a></li>
        <li class="dropdown-divider"></li>
        <li class="dropdown-submenu">
          <a class="dropdown-item" tabindex="-1" href="#">Hover me for more options</a>
          <ul class="dropdown-menu">
            <li class="dropdown-item"><a tabindex="-1" href="#">Second level</a></li>
            <li class="dropdown-submenu">
              <a class="dropdown-item" href="#">Even More..</a>
              <ul class="dropdown-menu">
                <li class="dropdown-item"><a href="#">3rd level</a></li>
                <li class="dropdown-submenu"><a class="dropdown-item" href="#">another level</a>
                  <ul class="dropdown-menu">
                    <li class="dropdown-item"><a href="#">4th level</a></li>
                    <li class="dropdown-item"><a href="#">4th level</a></li>
                    <li class="dropdown-item"><a href="#">4th level</a></li>
                  </ul>
                </li>
                <li class="dropdown-item"><a href="#">3rd level</a></li>
              </ul>
            </li>
            <li class="dropdown-item"><a href="#">Second level</a></li>
            <li class="dropdown-item"><a href="#">Second level</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</div>

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

The DIV element fails to encompass all of its content

There seems to be an issue with the only div element on my page. It's covering the middle of the page, but I managed to make it extend all the way down using CSS tweaks. However, there is a problem - the video inside the div is overflowing: Below is ...

Tips for eliminating the gap between Bootstrap 4 columns

Is there a way to eliminate the spacing between Bootstrap columns? I have three columns set up using Bootstrap but no matter what I do, I can't seem to get rid of the space between them. <!doctype html> <html lang="en> <head> ...

Unlocking the full potential of parsing messages using google protobuf-js

Currently, I am developing a front-end application using Angular5+ that utilizes google-protobuf JS and WebSocket for backend communication. Within my .proto files, I have defined 2 objects: a Request object. a Notification object. I have created a han ...

Modify the disabled background color of the mat-form-field component in Angular version 15

Is there a way to customize the background color and outline of disabled text input in Angular 15? I attempted using mdc-text-field--disabled and overriding the outline CSS, but it had no effect. Current appearance when disabled .mat-mdc-input-element { ...

Design of website built on Bootstrap framework seems distorted on Firefox browser

I built this website with the help of Bootstrap and you can view it at js-projects. Everything looks great when I open it in Chrome or Safari, but there are weird white strips that resemble scroll bars when I view it in Firefox. Can someone assist me in ...

How to apply hover effect to an image within a div using TailwindCSS

Is there a way to animate only the image and not the entire card (div) when hovering over it? I want specifically for the image to perform an animation, such as bounce effect. I'm using next/image for displaying the image. Can this animation be achie ...

Refresh Angular page data following new routing paths

The chat box page in the image below was created using Nebular: Nebular Documentation View Chat Box Photo After clicking on one of the user names (2) from the list, the URL ID (1) changes but the corresponding data does not load. Note: I have created a m ...

angular2 and ionic2 encounter issues when handling requests with observable and promises

I am attempting to trigger an action once a promise request has been resolved, but I'm having trouble figuring out how to achieve this. After doing some research, I learned that Ionic2 storage.get() returns a promise, and I would like to make an HTTP ...

Center the text vertically within a card using Vuetify styling

I am seeking a way to vertically align text within a card using Vuetify or traditional CSS in a Vue project. Here is my code: <template> <div> <v-container class="my-5"> <v-row justify="space-between"> <v- ...

Implementing Angular *ngFor to Reference an Object Using Its Key

myjson is a collection of various hijabs and headscarves: [ { "support": 2, "items": [ [ { "title": "Segitiga Wolfis", "price": 23000, "descripti ...

How can I safeguard my HTML and CSS content from being altered using tools similar to Firebug?

Is there a method to deter the alteration of HTML and CSS components on a webpage using tools similar to Firebug? I have noticed that certain users are changing values in hidden fields and modifying content embedded within div or span tags for their perso ...

Fuzzy text in drop-down box on Chrome, clear on Firefox

I've encountered an issue with a dropdown menu in Google Chrome where the content appears blurry, while it displays correctly in Firefox. The problem arises when the dropdown exceeds a certain height, and I've tried setting a max-height with over ...

Submitting JSONL String to a REST API using Angular: A Guide for Sending Data as a File via POST Method

I am currently developing an Angular App that integrates with OPENAI APIs, specifically focusing on their Upload function. The API Endpoint for this function is named "files" and you can find detailed documentation here When testing the request using Pos ...

Creating an HTTP gateway with Observables

When dealing with multiple requests, I need to pause them until the authentication of the http request has been confirmed. Essentially, I require an http gate where some requests can pass without authentication, while others need to wait for the token to b ...

Text with background coloring only

My text background always extends beyond the screen. Can anyone help me figure out what I'm doing wrong? Here is the HTML code: <div class="textSlide"> <span id="firstTitle">We assist you in finding all the individu ...

Using -webkit-transform with varying transition durations for rotateX and rotateY properties

Is it possible to have different transition times for both rotateX and rotateY in CSS3? I know you can use -webkit-transition to set a time, but it seems like setting separate transition times for both is not doable. It appears that you can only set it for ...

Is it feasible to organize checkboxes into columns using CSS?

Can checkboxes be reflowed into columns horizontally as the container's height changes dynamically with an unknown number of checkboxes? Here is a visual representation to illustrate the concept: Height = 180px (20px * 9 checkboxes): [ ] Checkbox 1 ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

Would you like to store modified CSS properties in a cookie?

Currently, I am facing a challenge while working on an ASPX page where CSS is used to define DIV properties. Although these properties can be altered on the page, they do not reflect when attempting to print them. Is there a method to modify CSS properties ...

CSS: Preserve HTML elements and only conceal the text within an <a> tag

Inside an "a" element, there's an image followed by text as a link. I'm looking to only hide the text of the link without affecting the display of the image. <a href="https://www.example.com/page"> <img src=" ...