Is it possible to customize the click background color of a Bootstrap dropdown menu?

I'm trying to change the background color of my bootstrap dropdown menu to red when clicked, instead of the default blue.

<div class="input-group mb-3">
        <div class="input-group-prepend">
            <button class="btn btn-outline-danger dropdown-toggle" type="button" data-toggle="dropdown"
                aria-haspopup="true" aria-expanded="false" id="dropdowns" id="chosen-q10">Make a Selection<span
                    class="caret"></span></button>
            <ul class="dropdown-menu" id="dropdown-q10">
                <li class="dropdown-item" data-value="#">1 (Strongly Disagree)</li>
                <li class="dropdown-item" data-value="#">2 (Disagree)</li>
                <li class="dropdown-item" data-value="#">3 (Neutral)</li>
                <li class="dropdown-item" data-value="#">4 (Agree)</li>
                <li class="dropdown-item" data-value="#">5 (Strongly Agree)</li>
            </ul>
        </div>
    </div>

Here is the code I have come up with:

.input-group .input-group-prepend .btn .dropdown-menu > li.open:focus {
  background-color: red;
}

However, it appears that this code is incorrect. Can someone help me figure this out?

Answer №1

Consider using the active state instead of focus, and try applying the "dropdown-item" class like so:

.dropdown-item:active {
    background-color: red;
}

Check out this fiddle demonstrating the solution: https://jsfiddle.net/7d2mkpx1/1/

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 error at line 72 of proxyConsole.js is: TypeError - Unable to access the 'default' property of an undefined object

I am new to using react redux loading bar and redux forms After clicking a button, I want the loading bar to display. The issue arises when I try to load the loading bar, resulting in the following error message: proxyConsole.js:72 TypeError: Cannot read p ...

`Is it possible to utilize bootstrap in order to structure rows with three elements each?`

My goal is to create a layout similar to this using Bootstrap 4: https://i.sstatic.net/EF4lL.png, where there are 3 elements displayed in each row. The elements I want to display are as follows: <div class="sprite d-inline-block bg-info rounded p-1 m- ...

How to eliminate padding between Bootstrap col-xx columns

When using Bootstrap's col-xx classes, the padding can sometimes result in wasted space on smaller screens. To address this, I have decided to remove the padding by nesting col-xx with specific CSS settings like shown below: <style> div[class^= ...

css background is repeating after the height of the div is reset

I'm working on a project where I want to resize an image while maintaining its aspect ratio to fit the height/width of the browser window. However, every time the code for resizing is implemented, the div height continues to increase with each resize ...

Ad blockers are causing this CSS class to be hidden

While most ad blockers do not have any issues with this specific class, some may hide the entire anchor block causing visitors to report missing text on the page. The class is used for hotlinked text that sends a tweet, as shown in the example below: < ...

Using JavaScript to we can transfer the function result to an HTML input field

Is there a way to display the result of a JavaScript function in an HTML input field? Here is an example form: https://i.sstatic.net/HHHl2.png When I click "Run - Script," the following simple script is executed: <button type="submit" class="btn btn ...

"Uncovering the mystery of the missing element in Jquery's open

I have developed a click-to-show feature that opens and closes a div from left to right. You can view the demo here on jsfiddle.net In the demo, you will find a green-colored div. Upon clicking this div, another div opens from left to right. An interesti ...

The hover effect does not work when clicking the mouse button in the Chrome browser

All: [UPDATE] Another method I discovered to achieve this is not a solution, but rather a workaround: Utilize the mousedown event as a trigger (since a drag action is needed, a mousedown event is required), within that, attach a mouseover event to that sp ...

What is the best way to populate data with Angular framework in my specific situation?

I'm currently working with Angular and attempting to implement a pagination feature. Here is what I have so far: Angular controller appModule.controller('testCtrl', ['$scope', function ($scope) { $scope.numbers = 7; }]) html ...

Unable to remove the dropotron transparency from the menu dropdown

I'm currently working with a CSS template that includes a Dropotron for JQuery menu animation. I've run into a problem trying to remove the transparency effect on the dropdown menu. Oddly enough, the second dropdown labeled "About Us" appears sol ...

What is the best way to incorporate TypeScript variables into CSS files?

In my Angular project, I am aiming to utilize a string defined in Typescript within a CSS file. Specifically, I want to set the background image of a navbar component using a path retrieved from a database service. Although I came across suggestions to use ...

Troubleshooting a problem with the navigation links on a single-page website with a

https://i.sstatic.net/5xcv9.png My website alampk.com features a single page layout with a fixed navbar at the top. However, when I click on links like exp, portfolio, etc., the section moves to the top but a portion of 50px gets covered by the navbar. I ...

whole <li> tag with both <a href> and <span> elements to create a clickable link

[RESOLVED] Solution found: I finally realized that the closing </a> tag comes before the <span> tags in the initial HTML code provided in the question, which was causing the issue! Thank you to everyone for your assistance!! This just goes to s ...

Switching images upon hovering in AngularJS

Looking to change images on hover in my Angular app, encountered site peculiarities making CSS solution impractical. Resorted to using ng-mouseenter and ng-mouseleave for image swapping instead. landing.jade img.share-button(src='images/btn_share.p ...

Adjusting the vertical alignment of wrapped divs with jQuery toggle

I am currently working on a project where I have a set of dynamically generated divs, each containing rows of content with three columns. Using jQuery toggle, I am trying to show and hide certain elements within the divs without affecting their layout. Her ...

What causes IE11 to sporadically run inappropriate media queries?

My website has been displaying incorrectly on IE11 due to a media query being executed for widths less than 767px, even though the window width is actually more than that. Interestingly, this issue only occurs randomly and never when the debug window is op ...

JavaScript (Create a button that toggles the visibility of an element)

I have implemented a hamburger menu that transforms into an x when clicked. I am looking to modify it so that clicking on the hamburger opens the menu, and clicking on the x closes the menu. Below is the code I have been working with: <!DOCTYPE html&g ...

Replace !important with JavaScript/jQuery when using animate()

I need to animate the background-position-x, but there is a background-position: 0 0 !important; set in the css that cannot be removed. Is it possible to work around this using JavaScript? My jQuery code is functioning as intended, but it is being overridd ...

The height of my text input box in HTML and CSS keeps fluctuating

I've encountered an issue while creating a search bar. The text input box and search button are positioned next to each other as intended, but the height of the input box fluctuates when I expand the browser window. I have thoroughly reviewed my code ...

Creating visually appealing websites is made easy with Bootstrap 5's innovative image and

I am working on a Bootstrap 5 website template and I want to add text with a white background in the center of an image. Instead of seeing just a white color over the image, I would like to have a white rectangle with a title and text centered on the imag ...