Transforming the hue of a Bootstrap button

I'm feeling a bit frustrated because I expected my code to work and shouldn't have to ask this question.

Currently, I am working with bootstrap and trying to customize the default blue color of the btn btn-primary class to something different.

My HTML snippet looks like this:

<input type="text" class="form-control" placeholder="Search by user name, member type, genre...">
                         <span class="input-group-btn">
                             <button class="btn btn-primary" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
                         </span>

This is the CSS that I wrote:

.btn btn-primary:hover,
.btn btn-primary:focus,
.btn btn-primary:active,
.btn btn-primary.active {
  color: #ffffff;
  background-color: pink;
  border-color: pink;
}

Despite my efforts, the button still appears as it did before:

https://i.sstatic.net/b0h4R.jpg

Answer №1

When the class btn is shared with another element named btn-primary, your CSS selectors should be adjusted as follows:

.btn.btn-primary:hover,
.btn.btn-primary:focus,
.btn.btn-primary:active,
.btn.btn-primary.active {
  color: #ffffff;
  background-color: pink;
  border-color: pink;
}

Answer №2

Make sure that your custom override is loading AFTER the default bootstrap, or if you are using npm and compiling your own version, ensure that your variable overrides come after the bootstrap defaults

In the bootstrap.css (BS4), the btn-primary classes are defined as follows: (Please note that it is NOT required to prefix these classes with .btn.btn-primary, just .btn-primary... The previous answer may not be entirely accurate, but it works due to specificity. :-)

.btn-primary {
  color: #fff;
  background-color: #007bff;
  border-color: #007bff;
}

.btn-primary:hover {
  color: #fff;
  background-color: #0069d9;
  border-color: #0062cc;
}

.btn-primary:focus, .btn-primary.focus {
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5);
}

.btn-primary.disabled, .btn-primary:disabled {
  background-color: #007bff;
  border-color: #007bff;
}

.btn-primary:active, .btn-primary.active,
.show > .btn-primary.dropdown-toggle {
  background-color: #0069d9;
  background-image: none;
  border-color: #0062cc;
}

If you are making modifications in your theme, just ensure that your theme changes load after the bootstrap styles do.

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

Influence of scoped styles on external webpages

I'm facing an issue with my nuxt app where I have two pages, each with different background styles. However, the background of one page is overriding the other. index.vue <style scoped> body { background-color: #ffffff; } #banner { backgr ...

Guide to utilizing the scrollspy feature in Bootstrap 4

Looking for guidance with HTML, Bootstrap, and CSS. I'm revamping a website page by implementing scrollspy in a list. The HTML is generated by R using the postcards package. This is my HTML code which utilizes Bootstrap 3.4.1. Transitioning to newer ...

My stored variable in the php session is not being recalled properly

Currently, my PHP script is generating new files based on user input. I want all documents to be created using the initial input to ensure consistency. In the first PHP script, I set the variable as follows: session_start(); $_SESSION["FirstName"] = $_POS ...

Determine the number of elements chosen within a complex JSON structure

I need to figure out how to count the length of a jsonArray, but I'm stuck. Here's an example to start with: https://jsfiddle.net/vuqcopm7/13/ In summary, if you click on an item in the list, such as "asd1", it will create an input text every t ...

What could be causing my content to unexpectedly break out of its designated div structure?

My website on Wordpress is causing me trouble. When I input text directly into the HTML/CSS structure hardcoded style, it fits perfectly. However, when I attempt to do the same thing using Wordpress <?php echo the_content();?>, it ends up breaking ou ...

Adding an asterisk to mark a required field in Angular reactive form inputs is a simple task that can be accomplished with just a

Currently, I am in the process of developing an application that utilizes a reactive dynamic angular form. The fields for this form are retrieved from an API request and generated dynamically. I have encountered the need to include a 'required field& ...

Steps for designing a fully responsive box-grid featuring 12 identical images with perfectly centered text

I've been struggling for hours trying to solve this problem and I could really use some advice: My goal is to create a fully responsive grid of equal-sized images (400px x 400px each) with centered text using Bootstrap 3. The grid should span 100% of ...

I will receive a 404 error if I try to access a URL without including the hashtag symbol

Is it feasible to display a record by directly inputting the user ID in the URL without using the # symbol? I am currently working on a website where I have a single view page named Login.html. I want to be able to access this page by entering the user&ap ...

Creating a Bootstrap layout with a cool typing effect to position my P element in the center of a div

I've been attempting to center my text with a typing effect in the middle of this div, but I'm having trouble getting it to work. Below is the code I tried using, but it's not achieving the desired result. The text continues to display on th ...

Use JavaScript to create a new window and load the HTML content from an external URL

Just starting out with HTML and Javascript I'm trying to use JavaScript to open a window and load content from an external source. I attempted using document.write(), but it only works when I hardcode the HTML as input. Any suggestions on how to get ...

The program encountered an error while trying to access the undefined property '_header'

An issue arises when the app.use(express.static("web")) line is executed. var express = require('express')(); var app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); //app.get(&apo ...

What steps should I take to customize prettier for Vue.js template syntax?

I need to modify a specific feature in Prettier. I'm curious if there's a simple method to incorporate the solution below without creating a custom parser. My .prettierrc.js: module.exports = { $schema: 'https://json.schemastore.org/pret ...

Aligning the navigation bar items in Bootstrap 4 (version alpha 5)

I have been exploring ways to center the navbar content in Bootstrap 4, alpha 5. After some research, I came across a suggestion involving the use of d-block and mx-auto. However, I am struggling to figure out how to center the navigation links so that th ...

Why is my AngularJS application triggering two events with a single click?

<button id="voterListSearchButton" class="serachButton" ng-click="onSearchButton1Click()">find</button> This button allows users to search for specific information: $scope.onSearchButton1Click = function() { var partId = $("#partIdSearch" ...

Tips for Choosing Two Classes Using CSS

I'm currently exploring ways to select two classes so that when one of them is hovered over, a specific animation will occur. Here is my latest attempt: .news1 { -webkit-filter: blur(3px); filter: blur(3px); -webkit-transition: .3s ease-i ...

Cordova - Fixed elements flicker/blink when scrolling

I have exhausted all possible solutions, ranging from -webkit-transform: translate3d(0,0,0); to -webkit-backface-visibility:hidden but none of them seem to resolve the issue of an element flickering/blinking/disappearing when scrolling on iOS with - ...

Issue with flex-grow property not functioning as expected in Internet Explorer 11

Hello! I'm running into an issue with flexbox in Internet Explorer: http://jsfiddle.net/EvvBH/ I've noticed that the #two element has flex: auto, which is meant to make it expand to fill the container, even if there's limited content. Ho ...

Using CSS3 to style a span element as a circular shape with one half displaying a distinct background color

Hey there! I've come across a little challenge with an HTML layout - the tricky part is that I can only tweak the CSS, not the actual HTML structure itself. The goal is to create a circular design (like the one shown in the image) using the border-rad ...

Leveraging the power of ExpressJs to incorporate a dynamic Navbar onto

ExpressJS and EJS are my chosen technologies for creating Views. When it comes to the navigation bar, I want to add a class="active" to the links that represent the current page. However, if I use partials in my views, how can I achieve this? Here is a q ...

Create HTML code automatically from JSON data

Currently, I am in the process of developing a template system. The concept is that an ordinary user can create a JSON file which will then be used by the system to automatically generate HTML code. However, I am facing some challenges and feeling a bit lo ...