When I incorporate a gradient, the background of my Bootstrap button flickers when clicked

I have implemented Bootstrap 4 with the following code snippet:

<!-- Flickers on click -->
<a href="javascript:void(0)" class="btn btn-primary">.btn .btn-primary</a>

<!-- Does not flicker on click -->
<a href="javascript:void(0)" class="btn-primary">.btn-primary</a>

<!-- Does not flicker on click -->
<a href="javascript:void(0)" class="button">.button</a>

Upon applying a gradient to the buttons, I am experiencing a strange flickering effect. Below is the CSS code related to the buttons:

.btn {
    transition: all .3s ease;
    border-radius: 3px;
    padding: 5px 15px;
}
.btn-lg {
    padding: 15px 25px;
}
.btn-primary {
    background: #556270;
    background: -webkit-linear-gradient(to right, #FF6B6B, #556270);
    background: linear-gradient(to right, #FF6B6B, #556270);
    color: white;
    border: 0px;
    padding: 5px 15px;
    border-radius: 3px;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:hover:active {
    background: #11998e;
    background: -webkit-linear-gradient(to right, #38ef7d, #11998e);
    background: linear-gradient(to right, #38ef7d, #11998e);
    color: white;
    outline: none !important;
}
.button {
    display: inline-block;
    padding: 5px 15px;
    background: #556270;
    background: -webkit-linear-gradient(to right, #FF6B6B, #556270);
    background: linear-gradient(to right, #FF6B6B, #556270);
    color: white;
    transition: all .3s ease;
    border-radius: 3px;
}
.button:hover, .button:focus, .button:hover:active {
    background: #11998e;
    background: -webkit-linear-gradient(to right, #38ef7d, #11998e);
    background: linear-gradient(to right, #38ef7d, #11998e);
}

For a visual demonstration of the issue, please refer to the following gif: https://gyazo.com/3d584bae179e7d3bda7f5610d3145f8f

I suspect that the flickering effect is associated with the .btn class, but I have not been able to identify any relevant code in Bootstrap 4 that would cause this problem.

Answer №1

A problem arises from the CSS code in bootstrap that causes the background-image to disappear in the :active state

.btn:not(:disabled):not(.disabled).active, .btn:not(:disabled):not(.disabled):active {
    background-image: none;
}

To fix this issue, you can include the :active in your style rules:

.btn {
  transition: all .3s ease;
  border-radius: 3px;
  padding: 5px 15px;
}

.btn-lg {
  padding: 15px 25px;
}

.btn-primary {
  background: #556270;
  background: -webkit-linear-gradient(to right, #FF6B6B, #556270);
  background: linear-gradient(to right, #FF6B6B, #556270);
  color: white;
  border: 0px;
  padding: 5px 15px;
  border-radius: 3px;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:hover:active,
.btn-primary:active{
  background: #11998e;
  background: -webkit-linear-gradient(to right, #38ef7d, #11998e);
  background: linear-gradient(to right, #38ef7d, #11998e);
  color: white;
  outline: none !important;
}

.button {
  display: inline-block;
  padding: 5px 15px;
  background: #556270;
  background: -webkit-linear-gradient(to right, #FF6B6B, #556270);
  background: linear-gradient(to right, #FF6B6B, #556270);
  color: white;
  transition: all .3s ease;
  border-radius: 3px;
}

.button:hover,
.button:focus,
.button:hover:active,
.button:active{
  background: #11998e;
  background: -webkit-linear-gradient(to right, #38ef7d, #11998e);
  background: linear-gradient(to right, #38ef7d, #11998e);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Flickers on click -->
<a href="javascript:void(0)" class="btn btn-primary">.btn .btn-primary</a>

<!-- Does not flicker on click -->
<a href="javascript:void(0)" class="btn-primary">.btn-primary</a>

<!-- Does not flicker on click -->
<a href="javascript:void(0)" class="button">.button</a>

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

An issue with the animation script in Ionic

I'm having trouble converting this to an Ionic application. Here's my code sample. Can anyone help me with putting this code correctly in Ionic? I'm trying to achieve something like this example <script src="https://cdnjs.cloudflare.com ...

What is the best way to place this dropdown in a fixed position within a parent element with overflow scrolling

I am facing an issue with a dropdown menu inside a parent div. The parent div has a fixed height and is set to overflow: auto. My goal is to have the menu extend beyond the boundaries of the parent when opened, but currently it just increases the height of ...

List of elements inside an HTML box

In my current HTML project, I am trying to include a box on a webpage that contains a scrollable list of elements. I want the content inside the box to scroll independently without affecting the rest of the page. Is there a way to achieve this? ...

The calendar on the Datetimepicker is not appearing in the proper position

I have encountered an issue while using Eonasdan bootstrap datetimepicker in a paramquery grid. Whenever I open the datetimepicker, the calendar appears hidden inside the grid. To tackle this problem, I added the following CSS condition: .dr ...

Converting Scalable Vector Graphics to Hypertext Markup Language and

So I've got this SVG file called 7.svg. What's the best way to show this image using HTML or CSS on my index.html page? ...

Creating hyperlinks to files dynamically in Angular can be easily achieved by utilizing JSON $ref

My Angular website includes a Bootstrap card that utilizes *ngFor to display a title, document name, and extension. Here is an example: https://i.sstatic.net/wi2Zx.png I would like the "handbook_2017.pdf" to be a clickable hyperlink that opens or downloa ...

Shifting hues of dots within a grid according to the passing of time

As a newcomer to the world of coding, I have conceptualized an idea for a visually appealing clock. My goal is to visually represent the passage of time throughout the day. To achieve this, I have devised a grid system where each dot on the grid represents ...

Creating a border around an SVG element using the background color of its parent container

I am aiming to layer 2 SVGs on top of each other. The top SVG will have an outline to make it stand out more from the bottom SVG. These SVGs are embedded on buttons with transitions and hover colors. I want the outline SVG to match the background color of ...

Problem with CSS: The fixed footer is too wide when set at a width of 100%

I'm experimenting with using percentages instead of pixels and noticing some unusual behavior. Why is my footer extending to the right (beyond the "pagePlaceHolderInner" element)? It works when I assign a specific pixel value to both elements ("pagePl ...

Align elements vertically in flexbox container using Bootstrap 3 on Internet Explorer 10 and 11

Encountering a problem in IE10+11 when trying to vertically center two Bootstrap columns within a row using flexbox. The dynamic content in the columns requires the row to have a minimum height of 65px. However, if the content expands and spans multiple l ...

What causes the "v-col" width to suddenly alter after adding the "bg-red rounded" class?

I'm struggling to organize the data into blocks using Vuetify. When I apply the "bg-red rounded" class to the "v-col", it alters the width of the column, resulting in an undesired grid structure. Here is the template section of my Vue file. Some data ...

Utilize jQuery to dynamically add a CSS class to a button

When using jQuery to create dynamic buttons, is there a way to add a CSS class to the button during creation without needing an extra line of JavaScript to add the class afterwards? Below is a example code snippet: $.each(data, function (index, value) { ...

CSS experts caution that the addition of margin and padding can cause the screen to jump

When I apply margin and padding to this class, it starts glitching like in the second GIF. However, if I remove margin and padding everything works fine, but I do need them for styling purposes. What could be causing this issue and how can I resolve it? ...

Expanding the Bootstrap Utility class within an SCSS stylesheet

Utilizing Bootstrap's utility classes in my scss file has been a recent experiment of mine. For instance: .pageTitle { @extend .p-3, border-bottom: 1px solid red} My current approach to importing Bootstrap involves using this code: @import '~b ...

Enhance your content with stylish text additions

Can anyone help me with merging 2 pieces of text in React JS, where one part of the text has unique styling? Below is an example of the code: <div> <div> {'If you haven\'t received an email, please check your spam filte ...

Ways to determine if an AngularJS modal is currently displayed

I am currently in the process of determining whether a modal is opened or closed. However, I keep encountering an error that says "cannot read property of open." To address this issue, I realize that I need to connect with $modal.open and retrieve the resu ...

The overflowing issue with the Nextjs Tailwind Marquee Component is causing a display

I've recently developed a unique nextjs/tailwind component. This component displays an isometric marquee that scrolls horizontally. However, I'm facing an issue where the content overflows to the right and causes the page to become horizontally s ...

Unusual Blank Space Found Beneath a Displayed Block Item

I've noticed some odd whitespace appearing under all my display: block elements within a meganavigation. Despite adding the code snippet below (which also determines column widths), I can't seem to pinpoint what's causing this issue. Wheneve ...

Is there a way to alter visibility once a radio button has been selected?

I have a shape resembling a cube with 4 faces, all of which are currently visible. However, I would like to hide the other 3 faces when one face is showing. For example: I attempted setting the opacity of the other cube sides to 0 when the first radio but ...

Centering a form on a webpage with Bootstrap: A step-by-step guide

Utilizing twitter-bootstrap for styling, I have implemented a login form and am attempting to center it on the page. Most suggestions on stackoverflow advise placing elements inside the container class, which is what I have done. The requirement is for t ...