Outline color of the side navbar menu and background color of the clicked navbar item

I am attempting to modify the outline color of the menu items which is currently set to grey. Additionally, I want to adjust the color of the menu items on smaller devices when a dropdown hamburger icon is clicked and the background color changes from grey to blue.

I have been unable to locate these specific styles in my CSS code, leading me to believe that Bootstrap CSS options are being utilized.

// Hide submenus
$('#body-row .collapse').collapse('hide');

// Collapse/Expand icon
$('#collapse-icon').addClass('fa-angle-double-left');

// Collapse click
$('[data-toggle=sidebar-colapse]').click(function() {
    SidebarCollapse();
});

function SidebarCollapse () {
    $('.menu-collapsed').toggleClass('d-none');
    $('.sidebar-submenu').toggleClass('d-none');
    $('.submenu-icon').toggleClass('d-none');
    $('#sidebar-container').toggleClass('sidebar-expanded sidebar-collapsed');

    // Treating d-flex/d-none on separators with title
    var SeparatorTitle = $('.sidebar-separator-title');
    if ( SeparatorTitle.hasClass('d-flex') ) {
        SeparatorTitle.removeClass('d-flex');
    } else {
        SeparatorTitle.addClass('d-flex');
    }

    // Collapse/Expand icon
    $('#collapse-icon').toggleClass('fa-angle-double-left fa-angle-double-right');
}
#body-row {
    margin-left: 0;
    margin-right: 0;
}



/* Sidebar sizes when expanded and expanded */
.sidebar-expanded {
    width: 230px;
}

.sidebar-collapsed {
    width: 60px;
}

/* Menu item*/
#sidebar-container .list-group a {
    height: 50px;
    color: black;
}

/* Submenu item*/
#sidebar-container .list-group .sidebar-submenu a {
    height: 45px;
    padding-left: 30px;
}

.sidebar-submenu {
    font-size: 0.9rem;
}

/* Separators */

/* Closed submenu icon */
#sidebar-container .list-group .list-group-item[aria-expanded="false"] .submenu-icon::after {
    content: " \f0d7";
    font-family: FontAwesome;
    text-align: right;
}

/* Opened submenu icon */
#sidebar-container .list-group .list-group-item[aria-expanded="true"] .submenu-icon::after {
    content: " \f0da";
    font-family: FontAwesome;
    text-align: right;
}

.menu-collapsed{
  color:black;
}

.sp
{margin-right: 20px;}

.list-group{
  margin-top: 140%;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="sss.css">
<script src="script.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd9f9292898e898f9c8dd0949e92938ebdccd3c8d3cd">[email protected]</a>/font/bootstrap-icons.css">

</head>
<body>


  <!-- Bootstrap NavBar -->
  <nav class="navbar navbar-expand-md">
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
          <i class="bi bi-list"></i>
</span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNavDropdown">
          <ul class="navbar-nav ml-auto">
              <!-- This menu is hidden in bigger devices with d-sm-none.
             The sidebar isn't proper for smaller screens imo, so this dropdown menu can keep all the useful sidebar itens exclusively for smaller screens  -->
              <li class="nav-item dropdown d-sm-block d-md-none">
                      <a class="dropdown-item" href="#top">Home</a>
                      <a class="dropdown-item" href="#top">Profile</a>
                      <a class="dropdown-item" href="#top">Tasks</a>
                      <a class="dropdown-item" href="#top">Etc ...</a>

              </li><!-- Smaller devices menu END -->
          </ul>
      </div>
  </nav><!-- NavBar END -->

  <!-- Bootstrap row -->
  <div class="row" id="body-row">
      <!-- Sidebar -->
      <div id="sidebar-container" class="sidebar-expanded d-none d-md-block">
          <!-- d-* hiddens the Sidebar in smaller devices. Its itens can be kept on the Navbar 'Menu' -->
          <!-- Bootstrap List Group -->
          <ul class="list-group">

              <!-- Menu with submenu -->
              <a href="#submenu1" data-toggle="collapse" aria-expanded="false" class=" list-group-item list-group-item-action flex-column align-items-start">
                  <div class="d-flex w-100 justify-content-start align-items-center">
                      <span class="fa fa-dashboard fa-fw mr-3"></span>
                      <i class="bi bi-pencil sp"></i>

                      <span class="menu-collapsed">Dashboard</span>
                      <span class="bi-layers-fill ml-auto"></span>
                  </div>
              </a>
              <!-- Submenu content -->
              <div id='submenu1' class="collapse sidebar-submenu">
                  <a href="#" class="list-group-item list-group-item-action     ">
                    <i class="bi bi-pencil sp"></i>
                      <span class="menu-collapsed">Chahgag</span>

                  </a>
                  <a href="#" class="list-group-item list-group-item-action     ">
                      <span class="menu-collapsed">Reports</span>
                  </a>
                  <a href="#" class="list-group-item list-group-item-action     ">
                      <span class="menu-collapsed">Tables</span>
                  </a>
              </div>

              <a href="#" class="list-group-item list-group-item-action">
                  <div class="d-flex w-100 justify-content-start align-items-center">
                      <span class="fa fa-tasks fa-fw mr-3"></span>
                      <span class="menu-collapsed">Tasks</span>
                  </div>
              </a>

              <a href="#" class="list-group-item list-group-item-action">
                  <div class="d-flex w-100 justify-content-start align-items-center">
                      <span class="fa fa-calendar fa-fw mr-3"></span>
                      <span class="menu-collapsed">Calendar</span>
                  </div>
              </a>

          </ul><!-- List Group END-->
      </div><!-- sidebar-container END -->

</body>
</html>

Answer №1

After clicking, do the dropdown items turn blue? If you inspect in devtools, you'll see that the background-color: blue is applied to the dropdown-item classes when they are in the :active state, which is when they are clicked.

https://i.sstatic.net/CWAmA.png

To change the blue color to something else when a dropdown item is clicked, you need to target the exact active state. This can be achieved using the :active CSS Selector.

In your CSS code, you would need to do something like this:

.dropdown-item:active {
    background-color: "your_color_here";
}

If this does not work, you can try adding !important:

.dropdown-item:active {
        background-color: "your_color_here" !important;
    }

I haven't tested any of these codes, so if you still have issues, feel free to share a codepen or snippet for quick and easy testing.

Answer №2

I have discovered the solution for the border color but am still searching for the answer to the second query.

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

Tips for referencing the team name and showcasing it in HTML despite the interference of the backslash character

{ offset: 0, results: [ { teamname_link/_text: "BAL", teamname_link: "", }, ...

Setting up Geolocation

I have been utilizing an APM tool for my work. The tool currently requires a pop-up in order to capture the user's location. However, there is now a need to capture the user's location without the pop-up appearing. Is there a method or workaroun ...

How can I incorporate a new object into an existing object in ReactJS?

I am facing an issue where I have an object named waA that is required in the final step. However, in ReactJS, the new object is not updating the previous object using a switch statement in a function. Below is the code for the object: waA = { jso ...

Generating columns dynamically in Angular Material 2

Exploring the functionalities of Angular Material ng-table, I am interested in dynamically generating columns. The code snippet provided below demonstrates a table template with statically defined columns. My goal is to replace these column definitions wit ...

Performing an HTTP POST request in Angular 2

After starting my work with Angular 2 and TypeScript, everything was going great. However, I encountered an issue when working with a REST API (POST) where the console log displayed Response {_body: "", status: 204, statusText: "Ok", headers: Headers, type ...

Animating splitting elements with VueJS

I am facing a challenge in creating a split animation with two icons. My goal is to split the icons with some translation in the X-axis after hovering on the container, but it seems like I am missing something in my implementation. The animation does not w ...

Linking from one page to another page within a specific region

After setting up a master header on my page, I found myself struggling to navigate from the second page back to the 'index' in order to reach a specific region known as #about. <a runat="server" href="~Index.aspx" class="smoothScroll"> ...

The div table that was created failed to display on the screen

In the process of developing a React web application, I am attempting to dynamically create a table based on selected data (users from a specific time period). While the user data is successfully downloaded, I am facing an issue with rendering the table. T ...

Leveraging Vue.js's computed properties to access and manipulate elements within an

I have a simple template that displays text from a wysiwyg editor using two-way data binding, as shown below: <template> <div> <quill-editor v-model="debounceText" :options="editorOptionProTemplate" > </qu ...

Bootstrap 4.1 does not display images properly

I am experiencing an issue where I am unable to see images that are uploaded in the wwwroot directory. The images vary in sizes. I am currently working with asp.net core and Bootstrap 4.1, and I suspect that the problem may be related to Bootstrap. https: ...

Error found when combining a stopwatch with the react useState hook and setInterval, causing an additional interval to start when the stopwatch

I have implemented a stopwatch feature that includes start and pause buttons. The start button triggers setInterval while the pause button calls clearInterval. Initially, pressing start and then pause works correctly. However, if you press start again afte ...

Using jQuery setTimeout within a forEach loop

Currently, I am fetching an array of messages using 'getJSON method. My intention is to display each message for 3 seconds before moving on to the next one. The process involves loading an HTML file and applying a CSS class to each message. However, m ...

Proceed to the following stage by clicking on an element in introJS

I'm currently developing a new application with angularjs and incorporating intro.js for a guided product tour. My goal is to allow the user to click on a specific element, causing intro.js to zoom in on that precise element instead of following the ...

Unable to loop through using ngFor

I have a component that retrieves data from the back-end and groups it accordingly. Below is the code snippet: getRecruitmentAgencyClientPositions(): void { this._recruitmentAgencyClientsService.getRecruitmentAgencyClientPositions(this.recruitmentAge ...

Modifying the appearance of a Component within a NavLink

I'm currently working on a navbar using NavLink from React-Router-Dom. It's fine to use the 'isActive' prop to style the active Link, but I'm stuck on how to style the subelements inside it. For more specific details, please take a ...

How come my h1 heading gets obstructed by the input box when the slideUp function is triggered

On my wikisearch page, I have a title and input box positioned around the middle of the page. When I click on the button, the title slides up along with the input box. However, the input box ends up covering the title completely. I'm trying to figure ...

I developed a digital Magic 8 Ball program, but unfortunately, it's only providing me with one response

I'm currently working on a Discord Bot for my friends and myself. One of the scripts I've created is an 8Ball script, but it's only giving me one answer. Here's the code snippet for my variable: var rand = ['Yes', 'No&apo ...

Display several modal pop ups using AngularJS

I'm currently using AngularJS and I have a requirement where I need to check if a student ID exists in the database when a user clicks a button. If the student ID is found in the database, I want to display #modal1, otherwise show #modal2. Is it achie ...

How to extract and compare elements from an array using Typescript in Angular 6

I have created a new Angular component with the following code: import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { HttpClient } from '@angular/common/http'; @Compone ...

Why isn't my Vue.js application automatically refreshing when I add or remove an object from the array?

In my Quasar and Vue.js project, I am working on a form where I can add objects to an array for insertion into the database simultaneously. However, I am facing an issue where the additions or deletions in the array only reflect on the screen after focusin ...