Tips for addressing the issue of button flickering due to CSS transitions

Is there a solution to prevent flickering without compromising the intended design? The issue arises when hovering over a moving or animated element and accidentally un-hovering because it moves beneath the cursor.

    <!DOCTYPE html>
<html>
<head>
<style>
body{
 background-color: #FFEE32;
}
.button {
box-shadow: -10px 10px;
    background-color: #FFEE32;
    border: 3px solid;
    display: inline-block;
    cursor: pointer;
    color: #202020;
    font-size: 30px;
    font-weight: bold;
    padding: 20px 30px;
      transition: all 0.15s linear 0s;
    text-decoration: none;
    position: relative;
    box-sizing: border-box;
    
}

.button:hover {
    top: 3px;
      transition: all 0.15s linear 0s;
    left: -3px;
    color: #FFEE32;
    background-color: #202020;
    border: #FFEE32;
    box-shadow: 0px 0px 0 #ffe800 !important;
    position: relative;

}

</style>
</head>
<body>

<h2>Animated Button - "Pressed Effect"</h2>
<div class="see">
<button class="button">Click Me</button>
</div>
</body>
</html>

Take a look at the example here and try hovering on the edges from the right and bottom.

Answer №1

If you want to enhance the hover effect on your button, consider adding an ::after pseudo element that is slightly larger than the button itself. This will create a smooth transition when hovering over the button, preventing any flickering or escaping from the cursor.

While this may not be a perfect solution, it can help solve your issue effectively:

.button:hover:after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  margin-left:10px;
  margin-top:-10px;
  height: 130%;
  width: 110%;
  /*border: 3px solid blue;*/
  box-sizing: border-box;
  padding:10px;
}

Uncomment the border: 3px solid blue rule to visualize the actual position and size of the pseudo element during hover.

Answer №2

Due to the border size and the top-left position, the button appears to be "flickering" when hovered over the corner side.

To fix this issue, add a 3px border and remove the top and left positions.

<!DOCTYPE html>
<html>
<head>
<style>
body{
 background-color: #FFEE32;
}
.button {
box-shadow: -10px 10px;
    background-color: #FFEE32;
    border: 3px solid;
    display: inline-block;
    cursor: pointer;
    color: #202020;
    font-size: 30px;
    font-weight: bold;
    padding: 20px 30px;
      transition: all 0.15s linear 0s;
    text-decoration: none;
    position: relative;
    box-sizing: border-box;
    
}

.button:hover {
    top: 0px;
      transition: all 0.15s linear 0s;
    left: 0px;
    color: #FFEE32;
    background-color: #202020;
    border: 3px solid #FFEE32;
    box-shadow: 0px 0px 0 #ffe800 !important;
    position: relative;

}

</style>
</head>
<body>

<h2>Animated Button - "Pressed Effect"</h2>
<div class="see">
<button class="button">Click Me</button>
</div>
</body>
</html>

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

What is the process for creating a personalized user input in JavaScript?

When entering a tracking number, please ensure it follows this specific format: AB-CDEFG-H. The first character (A) must be a digit between 1 and 9 inclusive. The second character (B) should be an uppercase English letter. This is followed by a hyphen (-). ...

The position of the carousel items changes unpredictably

My jQuery carousel consists of 6 individual items scrolling horizontally. Although the scroll function is working correctly, I have noticed that 2 of the items are randomly changing their vertical position by approximately 15 pixels. Upon reviewing the HT ...

Delete all pictures beginning with this specific ID from the posts

Currently, I have approximately 300 Wordpress posts, and each one contains a "tracking pixel" from a previously used service (which is implemented using IMG tags). This is an example of how it appears: <img id="serviceTrack_3274570" style="margin: 0px ...

Tips for transforming a container div into a content slider

Working with Bootstrap 3, a custom div has been created as shown below: <div class="second-para"> <div class="container"> <div class="second-section"> <div class="c ...

What is the best way to recreate this base with shadow, highlight effects, and a color that's not flat?

Click here to view the image I have successfully recreated part of it: a bottom with rounded corners, solid border, and solid colored background. However, I am struggling with achieving certain effects such as the highlighted top portion - where the backg ...

What could be causing the malfunction of Bootstrap Multiselect functionality?

I have been attempting to set up Bootstrap Multiselect but it simply refuses to work. Despite trying various solutions, I am unable to pinpoint the issue. My index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

Encountered an issue with instafeed.js due to CORS policy restrictions

Trying to implement an API that provides JSON data for use in a function. Required Imports: Importing Jquery, instafeed.min.js, and the API (instant-tokens.com). <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js& ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

Tips for effectively combining an array with jQuery.val

My goal is to have multiple form fields on a page, gather the input results into an array, and then store them in a database. This process was successful for me initially. However, when I introduced an autocomplete function which retrieves suggestions from ...

Is there a way to retrieve a numerical value from within two specific elements when web scraping?

I am new to web scraping and looking to extract the numbers located between the strong tags. Currently, I am using Python 3.8 along with BeautifulSoup for this task. <li class="price-current"> <span class="price-current-label"> </s ...

Use jQuery ajax to send form data and display the received information in a separate div

I'm working on a PHP test page where I need to submit a form with radios and checkboxes to process.php. The result should be displayed in #content_result on the same page without refreshing it. I attempted to use jQuery Ajax for this purpose, but noth ...

Creating a CSS grid with uniform row heights, each adjusting independently

I'm currently working on creating a CSS grid for a product display. My goal is to have rows with equal heights, but each row should adjust its height based on the tallest column within that specific row. Right now I have all rows set to be the same he ...

How can you deactivate all form elements in HTML except for the Submit button?

Is there a method available to automatically deactivate all form elements except the submit button as soon as the form loads? This would entail pre-loading data from the backend onto a JSP page while restricting user access for editing. Users will only be ...

The issue of jQuery's .last() function triggering multiple times with just a single click on the last

I currently have a set of tabs containing radio buttons and I need to trigger an event when the last option is selected (meaning any radio button within the final tab, not just the last radio button). Below is the HTML code: <div id="smartwizard" clas ...

Is there a way for me to implement my custom CSS design within the Material UI Textfield component?

I have a project in Next.js where I need to create a registration form with custom styles. The issue I'm facing is that I'm struggling to customize a textField using my own CSS. I attempted to use the makeStyles function, but encountered a proble ...

Experiencing an issue with referrer: The global symbol needs an explicit package name

my $refer = $ENV{HTTP_REFERER}; my $gk1 = substr($str1, -4); if ($gk1 = .swf) { my $antigk = "gk detected"; } else { my $antigk = $link; } I am encountering issues with this code after making some modifications. What could be causing the errors? I ...

Is there a way to adjust the padding temporarily?

Important Note: Despite the misleading title of my question, it doesn't accurately reflect my actual query (sort of). Below is the code snippet in question: .one{ background-color: gray; } .two{ padding: 20px; } <div class = "one"> < ...

React Animation Library With Smooth Initial Render and No Dependency on External Props

I'm currently implementing a Modal component within my app, utilizing Portals. My goal is for the Modal to smoothly fade in when it is rendered and fade out when it is no longer displayed. Upon examining the documentation for react-transition-group, ...

Enhance your web design with the mesmerizing jQuery UI drop effect combined

I'm attempting to create an animated toggle effect on a box using jQuery UI's drop feature. However, I've encountered some trouble due to the box having box-sizing: border-box applied which is causing issues with the animation. During the a ...

Issues with the execution of Jquery function

Hey guys, take a look at my code: //Additional Jquery codes // display_popup_crop : revealing the crop popup function display_popup_crop(link) { alert("show_popup_crop function is triggered!"); // changing the photo source $('#cropbox&a ...