Modify the color of the dropdown menu that is currently in use

I am a beginner in using bootstrap and I'm struggling to customize the CSS to my preferences. One issue I encountered is with a dropdown menu in my header where I managed to change the colors successfully. However, when the dropdown menu is selected, the font color remains unchanged. How can I adjust this? I attempted to use the following CSS code:

.dropdown-toggle:active, .open .dropdown-toggle {
        background:#ffffff !important; 
        color:#7dc623 !important;
    }
but it didn't have any effect.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
  <li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
  </li>
  <li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
  </li>
  <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
  <a class="dropdown-item" href="#">Link 3</a>
  <a class="dropdown-item" href="#">Link 4</a>
</div>
  </li>
</ul>
  </div>
</nav>

The background appears green but the text remains black, while it should be white.

View screenshot

Answer №1

To solve the issue, I simply removed the .open class from the code:

.dropdown-toggle:active, .dropdown-toggle {
    background:#ffffff !important; 
    color:#7dc623 !important;
}

Answer №2

It is recommended to apply your CSS properties directly on the a tag instead of using a span in between for text styling to avoid potential issues.

For example:

.navbar{
  background-color: #FFFF99 !important;
}

.text_in_span{
  color: #7dc623 !important;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
      <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#"><span class="text_in_span">Link 1</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#"><span class="text_in_span">Link 2</span></a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="text_in_span">Dropdown</span>
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="#"><span class="text_in_span">Link 3</span></a>
          <a class="dropdown-item" href="#"><span class="text_in_span">Link 4</span></a>
        </div>
      </li>
    </ul>
  </div>
</nav>

This approach should help resolve any potential issues, happy coding!

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

Text becomes jumbled when browser is resized with multiple words per line

https://i.sstatic.net/jCJxH.pngI am currently working with bootstrap 4, and I've noticed that when I resize the browser window, the label shifts to the next line and causes some layout issues. This behavior was not present in bootstrap 3. I haven&apos ...

Determine if a user has made any spelling errors within an HTML textarea using spellcheck

I am working with a textarea that has the following definition: <textarea spellcheck="true"></textarea> As users type, spelling mistakes are highlighted (such as with a red underline in my browser). Is there a way, possibly using jQuery, to v ...

Encountering issues with the functionality of my Bootstrap navbar

After diving into the world of bootstrap, I encountered some challenges with the navigation bar in mobile view. Despite adding a navbar and a toggle button, it doesn't seem to be functioning correctly. Following tutorials and examples meticulously, bu ...

Basic media query does not affect div resizing or font changes in Chrome or Internet Explorer

I am facing an issue with a simple media query that is not working as expected in Chrome or IE, but strangely it works fine in FF. I have tried various formulations of the media query without success. Any assistance would be greatly appreciated. Below is ...

Unable to align span vertically using font-style "Luckiest Guy" in CSS

I have encountered an issue with vertically centering a span using the font-style "Luckiest Guy". https://i.sstatic.net/Lz8o3.png I attempted to use display: flex;align-items: center; on the span, but it did not work. App.vue <template> <div ...

What is the best way to display a border around text in an HTML element when the mouse hovers over it?

I am currently developing a Browser Helper Object (BHO) for Internet Explorer that involves searching for specific words on a web page and encasing those words in an HTML tag for styling purposes. While I have code in place that allows me to change the st ...

Prevent Bootstrap cards from stacking at smaller screen widths including sm and xs sizes

When the page width drops below the md size, the cards begin to stack. How can I maintain the layout of the cards and prevent them from stacking when the screen size is sm or xs? This snippet shows the HTML code for the card components displayed in the im ...

How to retrieve the ID of a table column using jQuery in HTML

I am facing an issue with a HTML table that consists of only one row and one column: <table id="backlog"> <colgroup> <col width="200"></colgroup> <tbody> <tr><td id="91" tabindex="0" class="mark">BackLog&l ...

Adjusting the height of the search icon through the Jquery toggle action to create animated effects

While trying to create a search field with the click function (animate), I noticed an issue similar to what is seen in this example: . Whenever the search icon is clicked, it moves up and down unexpectedly, and I am uncertain as to why this behavior is occ ...

The functionality of the Checkbox is experiencing issues when used in conjunction with Bootstrap 5 and Vuejs

Here is a div showcasing an input with its label. However, there seems to be an issue where I am unable to click on the checkboxes. This code snippet serves as an illustration of utilizing Bootstrap 5 checkboxes within VueJs. <ul class="widget-lis ...

Arrange and overlay PNG images within a Bootstrap container using position:absolute

I've been attempting to align and stack some images within a bootstrap grid, but I'm having some trouble. Instead of aligning within the grid, the images seem to align to the window instead. I've been using position:absolute, which I found ...

Text off-center in Bootstrap Badge

I'm struggling to find a way to center my text with the icon properly. This issue is only happening in Google Chrome. You can view the problem in action on this code snippet. @import url('https://fonts.googleapis.com/icon?family=Material+Icons ...

JQuery UI Dialog not functioning properly as intended, failing to display

Issue: The dialog box is appearing without the buttons being pressed and it does not function as an overlay when activated. Any help would be greatly appreciated. Code: Includes: <script src="js/jquery-1.5.1.min.js"></script> <script src ...

Can the color of the expanded navigation bar in Bootstrap 4 be customized?

I'm currently in the process of developing a Bootstrap website and was wondering whether it is feasible to add a background color to the expanded navbar specifically on small screens. Feel free to refer to the images below for a visual representation ...

XPATH: Select the paragraph element that is directly followed by another paragraph element

Can anyone help me with selecting the first paragraph element that is directly preceded by another paragraph element? I have provided an example below to illustrate what I am looking for. <div class="vacancy-left"> <h2>Machine Operator / P ...

Include a hyperlink to a website that was created with the help of Photoshop

Is it feasible to incorporate a hyperlink into a website that was designed using Photoshop templates? In the past, creating templates in Photoshop and then adding links with tools like Dreamweaver was common practice. I believed that dynamically adding li ...

What is the method for initiating a radial gradient from the middle of the pie chart?

In my pie chart with grid lines, I have successfully implemented a radial gradient. However, the issue is that there is a separate gradient for each pie slice. What I really want is a single gradient originating from the center of the entire pie chart. I ...

Center align a row with the help of Bootstrap 4.0

Here is some code with Bootstrap 4 classes that I am working with: <div class="container"> <div class="row"> <div class="col-xl-4 col-md-6 col-lg-4"> <div class="footer_widget"> <h3 class ...

Guidelines for choosing input using jQuery

I am looking to retrieve the value of an input using jQuery. Specifically, I need to extract the value of a hidden input with name="picture" when the user clicks on the حذف این بخش button by triggering the function deleteDefaultSection( ...

The collapsible menu does not toggle when I tap on the icon

I am currently troubleshooting an issue with this link "https://sampledemos.online/training/index.html" where the toggle feature is not functioning properly. Below are the codes I have written: <aside id="layout-menu" class="layout-menu m ...