Is there a way to eliminate the button's background color when clicking on an area outside of it

I recently designed a search bar with a category dropdown button, and managed to successfully customize its hover, active, and focus states to remove the background color. However, I encountered an issue where clicking outside the button to close the dropdown reverts the button back to its original background color. Can anyone provide guidance on how to prevent this from happening? (Note: I am using Bootstrap 4)

Here's how the button looks when clicked on:

And here's how the button behaves when clicked outside:

.nh-searchbar-category-dropdown-btn {
  border: none;
  position: relative;
  left: 55px;
  color: $secondary-color;
}

/* CSS to hide the background color on hover, active, and focus states */

.nh-searchbar-category-dropdown-btn:hover,
.nh-searchbar-category-dropdown-btn:active,
.nh-searchbar-category-dropdown-btn:focus,
.nh-searchbar-category-dropdown-btn:focus:focus-within,
.nh-searchbar-category-dropdown-btn:visited,
.nh-searchbar-category-dropdown-btn:target,
.nh-searchbar-category-dropdown-btn:focus:focus-visible {
  background-color: transparent !important;
  color: $primary-color !important;
  transition: none !important;
  border: none !important;
}
<button class="btn btn-outline-secondary dropdown-toggle nh-searchbar-category-dropdown-btn" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false>
  <i class="far fa-bars"></i>
</button>

Answer №1

Stray away from the norm by deviating from Bootstrap's usual practices.

Stick to the following classes exclusively:

<button class="btn btn-link YOUR CHOSEN CLASSES EXCLUDING nh-searchbar-category-dropdown-btn" type="button">
  <i class="far fa-bars"></i>
</button>

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

Having trouble transferring a variable from getJSON data to PHP

I am encountering an issue with my jQuery getJSON method when trying to pass data to PHP. Strangely, I am unable to pass a variable. In another part of my code, passing the variable works fine. Additionally, hardcoding the string or using a valid variable ...

The alignment of the Bootstrap 4 row is off-center

My bootstrap structure includes a row with 4 columns, initially set up with 3 columns containing icons that aligned perfectly. Upon adding a fourth column, the new addition appears slightly lower on the page compared to the rest, resulting in misalignment. ...

Reset the child JSP page to its original appearance

Displayed below is a JSP page: <div id="tabs-7" style="width: 100%;"> <form:form id="deviceForm" name="" modelAttribute="" enctype="multipart/form-data"> <div class="inputWidgetContainer"> <div class="inputWidget"> <table> ...

Switch Image to Background Image on Mobile Devices

I am currently working on a website that needs a special page for an upcoming event. Typically, the pages on this site have a mast banner image that stretches across the full width of the page. However, for this particular page, it is necessary for the ima ...

When utilizing selenium to scrape an e-commerce platform, my scraper is limited to retrieving only the initial page of HTML content

When attempting to scrape data from tmall.com with selenium, I am encountering an issue where the program switches to another page but continues to retrieve the html content of the initial page. Even though the correct target page is being displayed in the ...

Creating React components with scoped CSS imports

I am facing an issue with my component's CSS structure and import method. About/style.css .AboutContainer { # Some style } p > code { # Some style } When importing the CSS in the component: About/index.js import './style.css&apos ...

Incorporate an icon into a text input field using Material UI and React

I have a form with a text input element: <FormControl className='searchOrder'> <input className='form-control' type='text' placeholder='Search order' aria-label='Search&ap ...

Updating Bootstrap Indicators with jQuery on Click Event

Unfortunately, I am unable to share an image due to limited internet data. My goal is to switch each image to its sprite equivalent. There are three list items that I'm struggling to change because they each have two classes that need to be updated. ...

Using AJAX to submit a form and then refreshing the page within the current tab

I am facing an issue with my web page that contains multiple tabs, some of which have forms. Whenever a form is successfully submitted, the page reloads but always goes back to the default first tab. To address this, I am attempting to use a storage variab ...

Adjust the color of the hyperlink within the Lightbox feature

I am currently using Lightbox Plus. I made some changes to the link colors in the Lightbox.min.css file: .lightbox a{ color: #E74C3C; } .lightbox a:hover{ color:white; } .lightboxOverlay a:{ color: #E74C3C; } .lightboxOverlay a:hover{ color:white; ...

Creating MySQL inserts from various dynamic HTML tables generated using PHP

Currently, I am faced with a challenge while working on a PHP file that produces multiple dynamic HTML tables through the use of an included PHP library. To provide a glimpse, here is a snippet of the HTML output (with just two tables and reduced rows) ava ...

Generate dynamic Bootstrap Carousel slides with unique hashtag URLs

I've been attempting to connect to various slides within a bootstrap carousel from a different page but have had no success. Here is an example of what I'm trying to achieve: <a href="services#slide2">Link to Slide 2</a> For refere ...

In Safari, the CSS filter value may not be applied immediately, whereas in Chrome it is

While dragging the input range, the brightness value (also a CSS property) updates but the image is not instantly affected in Safari. (It works well in Chrome) How can the changes be applied to the image while dragging? var app = Vue.createApp({ data() ...

Collapsing or expanding the Material UI accordion may lead to flickering on the page

import React from "react"; import { makeStyles } from "@material-ui/core/styles"; import Accordion from "@material-ui/core/Accordion"; import AccordionDetails from "@material-ui/core/AccordionDetails"; import Accordi ...

Guidelines for pinpointing local directories

Recently, I obtained a source code for a website navigation that includes a unique set of icons known as "Typicon." The HTML in the source code contains the following: <link rel="stylesheet" type="text/css" href="css/component.css" /> Within the C ...

How come the div element is not rendering the CSS styles?

What could be the reason for .header not displaying the background color and height settings? https://jsfiddle.net/f3puaeq6/1/ .header{ background-color: black; height: 300px; } ...

Build an upvote feature using PHP and WordPress that allows users to vote without causing a page reload

Just starting out as a developer and currently working on a website using WordPress. I want to implement an upvote button that allows users to upvote a post without the page needing to refresh. I understand that I'll need to use JavaScript to highligh ...

Migrating WordPress Gutenberg to a Separate React Component: Troubleshooting Missing CSS Styles

I am in the process of developing a standalone version of the Gutenberg block editor from Wordpress that can function independently outside of the Wordpress environment. My goal is to integrate the Gutenberg editor as a React component within an existing R ...

Display movie details in a responsive column layout that condenses into a single column

I'm having trouble displaying movie information on a website due to CSS and HTML issues. My goal is to align the title (Director:, Cast:, etc) with the first item in the list, and have all subsequent items follow below. I initially tried using a defin ...

CSS files are failing to load in ASP .NET framework

I am facing a similar issue to the one described by another user on Stack Overflow here: Asp.NET not applying my CSS files However, after adding the following code to my web.config file, nothing seems to change: <location path="css"> &l ...