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

Loading HTML content in a WPF WebBrowser without encountering security messages

Currently, I am developing a WPF application in which I create the content of an HTML file as a string (including some JavaScript functions for calculations). After generating the string, I save it as an HTML file on my local disk and then reload it using ...

Using Angular2, you can dynamically assign values to data-* attributes

In my project, I am looking to create a component that can display different icons based on input. The format required by the icon framework is as follows: <span class="icon icon-generic" data-icon="B"></span> The data-icon="B" attribute sp ...

Difficulty with Bootstrap 4 mobile navbar dropdown feature

<div class="baslik baslik1 baslik2 "> <nav class="navbar bg-light navbar-light navbar-expand-sm sticky-top "> <a href="./index.html" class="navbar-brand"><img src="img/512x512logo.png" ...

Display a specific message in a div when the input field is left empty

My goal is to create a div that mirrors the content of an input field. When I type "lalala" in the input, it should show up in the div, and this part is working fine. However, I also want the div to display "The input is empty" when the input itself is emp ...

Navigate through input fields while they are hidden from view

Picture this scenario: <div> <input tabindex="1"> </div> <div style="display:none"> <input tabindex="2"> </div> <div> <input tabindex="3"> </div> As I attempt to tab through these input f ...

In a React application, adjusting the main container height to 100vh results in the window.scrollY position being set to

I was facing problems with flashing on the Safari/Firefox browsers. By setting the main container height to max-height: 100vh, I managed to resolve the flickering issue. However, I am also looking for a solution to keep track of the window.scrollY positi ...

Which names can be used for HTML form tags in jQuery?

Recently, I encountered an issue related to jQuery form serialization which stemmed from naming a form tag "elements". The problem arose when using jQuery $(’form’).serialize(). Here is an example of the problematic code: <form> <input name=" ...

adding a new div to the bottom of a row that is being created on the fly

I encountered an issue where rows are created dynamically and I needed to add a div at the end of each row. Despite trying various methods, I faced difficulties as adding the div resulted in extra divs being added to all previous rows whenever a new row wa ...

Retrieve information from the database and showcase it in a competitive ranking system

Here is the HTML and CSS code for a leaderboard: /* CSS code for the leaderboard */ To display the top 5 in the leaderboard, PHP can be used to fetch data from the database: <?php // PHP code to retrieve data from the database ?> The current ou ...

Displaying content on a webpage using PHP, AJAX, and HTML

Looking to update my current form setup. I have a basic Form below: <form action="" method="POST"> <input type="button" value="Generate Numbers" onclick="on_callPhp1()"/> </form> Accompanied by this javascript code: <script type="te ...

What steps should I take to make my Twitter widget adaptable to varying screen heights?

I'm currently utilizing react-twitter-widgets to incorporate a Twitter timeline within my application. While everything is rendering correctly, the height of the timeline extends down the entire page. Is there a way to adjust the widget's height ...

What is the best way to ensure a jQuery UI slider recognizes when the mouse is released after being clicked?

I have integrated the jQuery slider into my application and am facing an issue with triggering an event to update the database upon releasing the slider. Currently, I am using the following code snippet: $('.ui-slider-handle').mouseup(function () ...

When floating divs with varying heights are wrapped, they may become stuck in place

Hey there! Let's tackle a challenge: I've got a few divs, each with varying heights. These divs contain portlets that can expand in height. Here's a basic example: .clz { float: left; } <div class="container"> <div class="cl ...

Guide to positioning an image next to text within a table: Utilizing jQuery DataTable to organize images alongside text in a table header

When using the jQUery DataTable plugin, I encountered an issue where the table header text and the image for sorting are not properly aligned. Here is how it looks: https://i.sstatic.net/Kqgz9.png (I want the arrow and the text to be aligned horizontally ...

Only a select few expandable elements in the jQuery accordion

How can I create an accordion menu with only a few expandable options? I am looking to include the following items in my menu: Home, Support, Sales, Other The "Home" option is just a link without any sub-menu. Clicking on it should direct users to a spec ...

Error in React regarding the tri-state checkbox's indeterminate state being null

I am attempting to create a triple-state checkbox in React. The functionality I'm aiming for is that each click on the checkbox will cycle through blank->checked->crossed->blank->.... After doing some research, I stumbled upon a helpful re ...

In Stripe.js, the background color and height of the credit card input cannot be customized

I'm struggling with customizing the appearance of a Stripe credit card input within my Vue.js application. I want to adjust the background color to #f1f1f1 and set the height to 60px, but despite trying both base styles and css, I can't seem to g ...

How to retrieve video duration in Angular 2 before uploading the file

Is there a way to retrieve the video duration before uploading it in Angular2? I am looking for a solution without using jQuery. Here is the code snippet I have so far: <input type="file" class="form-control" ng2FileSelect [uploader]="uploader" accept= ...

Generating HTML table rows dynamically in Angular based on the number of items stored in a $scope variable

In my current project, I am utilizing Angular to dynamically populate data in an HTML table. Instead of manually coding each row for display, I am in need of a solution that allows me to programmatically define each HTML row. The Angular controller snippet ...

Title of the most recently created file on GitHub

Being new to web designing and javascript, I am seeking help in understanding how to display the latest PDF file in my small website hosted on GitHub. Despite successfully displaying a PDF file, I encountered difficulties when attempting to showcase the mo ...