Customizing color schemes of bootstrap buttons and dropdown-toggle elements

My button group looks like this:

HTML

<div class="btn-group">
   <button type="button" class="btn btn-default btn-xs  red-outline-button"> Sync </button>
   <button type="button" class="btn btn-default btn-xs  gold-outline-button" data-toggle="dropdown">New PG </button>
  <ul class="dropdown-menu">
    <li><a href="#"> Test1</a></li>
    <li><a href="#"> Test2</a></li>
</ul>
</div>

CSS:

.red-outline-button:hover {
  border-color: #C4213C;
  background-color: #f8d3d9;
  color: #000
}

.gold-outline-button:hover {
  border-color: #B3892F;
  background-color: #f4ebd7;
  color: #000;
}

The current behavior is that the color changes when hovering over the buttons. However, when clicking and holding or opening the dropdown menu from the second button, the color reverts back to default gray.

I've attempted to use .red-outline-button:active without success.

So, my question is, what is the correct way to adjust the CSS color when:

  1. The button is clicked
  2. The dropdown menu is opened (only styling the button itself, not the dropdown)

Answer №1

To customize the Bootstrap classes, you can override them as follows:

 .btn-default.focus, .btn-default:focus

If you only want to override specific elements, you can use this code snippet:

.gold-outline-button:hover, .gold-outline-button.focus, .gold-outline-button:focus {
  border-color: #B3892F;
  background-color: #f4ebd7;
  color: #000;
}

For a demonstration of this customization, check out this link: http://www.bootply.com/Li7tkXlF9P

I hope this solution proves useful to you. :)

Answer №2

To customize the styling of a button, simply add .gold-outline-button:focus to the selector and use !important to override the default Bootstrap styles.

For example:

.gold-outline-button:hover, .gold-outline-button:focus {
  border-color: #B3892F !important;
  background-color: #f4ebd7 !important;
  color: #000 !important;
}

By following these steps, you can solve both Problems. You can view this customization in action here: https://jsfiddle.net/sytc4pc5/

Answer №3

To resolve this issue, simply ensure that the click event does not override the hover properties.

 .red-outline-button:hover,.red-outline-button:active,.red-outline-button:focus {
      border-color: #C4213C;
      background-color: #f8d3d9;
      color: #000
    }

    .gold-outline-button:hover,.gold-outline-button:active,.gold-outline-button:focus {
      border-color: #B3892F;
      background-color: #f4ebd7;
      color: #000;
    }

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

Strip the CSS styling from an image (the CSS being included in the generated code)

I need to remove the CSS styling from an image, but I can't modify the generated code where it's coming from. My actual code looks like this: <div class="bubble"> <img id="one" src="/static/webupload/MyronArtifacts/images/descarga.png ...

Utilizing a Single Background Image Across Several Div Elements

Let me illustrate my question using a sequence of images. The div container is set to display the background image as follows: In addition, there will be tile-shaped divs layered on top of the image: I aim to have the background image visible only withi ...

Enhance your website with a stylish drop-down menu from inc.com

I am trying to create a drop and hide menu effect similar to the one on Here is my current demo: http://jsfiddle.net/elementhttp/56ThC/ $("#1").mouseover(function(){ //alert("aaaaaaaaaa"); just for testing $(".block2").stop().fadeToggle(700 ...

Tips for displaying two dynamic variables that are interdependent

For instance: Controller: AllBooks[{ book1:{ hardcover{price:25.99},e-book{price:1.99} } }, book2:{ hardcover{price:60.00},e-book{price:2.99} }]; $scope.bookchoice = function(selectedBook) { $rootScope.choice = selectedBook;} $scope.booktype = functio ...

Implementing spacing to columns in Bootstrap 4

Is there a way to add margin to the "col" element with the class "mr-md-3" without causing any layout breaks within the containing div? .content { height: 200px; border: 1px solid black; } <script src="https://ajax.googleapis.com/ajax/libs/jquery ...

Centering text both vertically and horizontally over an image using CSS

I've been attempting to center the div banner_title both vertically and horizontally within another div in this way... .box { text-align: center; } .banner_title { font-size: 32px; position: absolute; top: 50%; width: 100%; } .banner_titl ...

Issue with jQuery AJAX call: When submitting an HTML form, control is not being returned to the calling

I am facing an issue with my HTML form where it is loaded correctly into the DOM through a jQuery ajax call. The problem arises when I submit the form data to a PHP module using another jQuery ajax call. Even though the network traffic shows that the form ...

Is there a way to obtain HTML code within a contentEditable DIV?

When working in a contentEditable-DIV, my goal is to extract the HTML code from the starting position (0) to the end position where the user has clicked. <div id="MyEditableId" contentEditable="true"> 1. Some text 123. <span style="background-c ...

Switch up the text inside a div using jQuery

I am developing a small grocery shopping application. My goal is to create a page where users can view the contents of their shopping cart by clicking a button. I have designed a template that displays the contents in a white space. The idea is to store ...

Execute the function when the control becomes visible

Currently, I possess an input control: <input id="someID" class="form-control" type="text" name="SomeData" data-ng-model="vm.SomeData"> I have a requirement to set the initial value of vm.SomeData upon user scrolling down to this control. As a begi ...

The art of jQuery: Effortlessly animate the deletion of a CSS property

When using jQuery, I often "collapse" certain DOM elements by decreasing their width to 0px and fading them out. Here is an example: $(".slideoutmenu").animate({ width: 0, opacity: 0}, function() { $(this).hide(); }); The widths of these elements can var ...

Having difficulty finding the close button in a pop-up window while using the Selenium library with Python

While using chromedriver to open the website mentioned below in my extract_data() function, I encountered a problem with dismissing a pop-up message by clicking the 'x' button. Surprisingly, it seems to click the wrong button instead. What' ...

Arranging div elements into columns side by side with Flexbox

I've been working on the frontend of my chat web app and recently discovered flexbox. I'm struggling to center two elements with a blue background below the "CHAT" heading, aligned with two green elements like a black square. My challenge lies in ...

Inadequate text alignment

Trying to create a header mockup for a website featuring branding elements like a logo and brand name. Utilizing Angular.js for the webpage development process, incorporating a URL for the logo image from an online source. Encountering alignment issues th ...

Align select and number inputs vertically in Firefox

How can I achieve vertical alignment for these inputs on Firefox? The alignment works perfectly in Chrome, Safari, and Opera, but not in Firefox (Version 57 tested on macOS, Windows, and Linux Mint). While removing type="number" from the input resolves th ...

Iterating through an SVG path multiple times

If I have the arrow below and I want to place it at various locations within the svg: <svg width="400" height="400"> <path transform="translate(150,100)" fill="black" d="M 0.5,0.5 l-100,0 -25,20 25,20 100,0 z" /> <path transform="translate( ...

Adjusting iframe height based on its source URL using JQuery

Currently, I have implemented a script to adjust the height of YouTube iframes in order to maintain a 16:9 aspect ratio while keeping the width at 100% of the container. The challenge I am facing is ensuring that the script only affects YouTube videos and ...

Anchoring HTTP headers in HTML tags

Currently, I am working on some code to enable dragging files from a web app to the desktop by utilizing Chrome's anchor element dragging support. The challenge I am facing is that certain file links require more than a simple GET request - they nece ...

Animate text and div elements with bounce or fade-in effects when they appear on the screen in a React application

Animating the elements of my website is a simple task for me, however I am looking to have them animate only when they are visible on the screen without relying on pixels or offsets. I want the animations to be responsive, even in phone mode, without hav ...

How can one get rid of a sudden strong beginning?

Recently, I delved into the world of CSS animation and encountered a frustrating issue. I've tried numerous methods and workarounds to achieve a smoothly looping animation without interruptions. Despite my efforts, I have not been able to replicate th ...