Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid flickering on box shadow transition?

Tags:

html

css

I have CSS that animates box shadow on hover. It works on Firefox but causes flickering in Opera/Chrome browser.

Is it possible to fix it without extra markup and without pseudo elements?

.hover {
    color: #fff;
    background:  rgba(0, 0, 0, 0.5);
    display: block;
    display: inline-block;
    text-align: left;
    cursor: pointer;
    box-shadow: inset 0 0 0 0 #fff;
    -webkit-transition: box-shadow linear 0.5s,color linear 0.5s;
    -moz-transition: box-shadow linear 0.5s,color linear 0.5s;    
    transition: box-shadow linear 0.5s,color linear 0.5s;
}
.hover:hover {
   box-shadow: inset 424px 0 0 0 #fff;
   color: #000;
}
<h1 class="hover">This is some really looong title!</h1>
like image 424
Dejo Dekic Avatar asked Oct 26 '17 17:10

Dejo Dekic


People also ask

How do you stop flickering in CSS?

Fortunately, several options are available to fix that : -webkit-backface-visibility: hidden; This CSS rule is designed to fix the flicker effect on Chrome-based browsers, applied to the HTML flickering element. But use it wisely : this rule works, but is not the most efficient way to avoid flickering effect.

Can you transition box shadow?

Transition shadowsYou can add transitions to box shadows so that interactions with them will be smooth. For example, you can add a hover effect to an element that will make the box shadow's color grow darker. Here are the steps: Add a box shadow to an element and style with black color and 20% opacity.


1 Answers

Try setting a boxshadow of .09px

.hover {
max-width: 400px;
    color: red;
    background-color:  blue;
    display: table;
    text-align: left;
    cursor: pointer;
    box-shadow: inset 0 0 0 0.09px white;    
    transition: all ease 5.5s;
}
.hover:hover {
    background-color:  blue;
   box-shadow: inset 440px 0 0 0 #fff;
   color: #000;
}
<h1 class="hover">This&nbsp;is&nbsp;some&nbsp;really&nbsp;looong&nbsp;title!</h1>

.hover {
    color: #fff;
    background:  rgba(0, 0, 0, 0.5);
    display: block;
    display: inline-block;
    text-align: left;
    cursor: pointer;
    box-shadow: inset 0 0 0 0.09px #fff;
    -webkit-transition: box-shadow linear 0.5s,color linear 0.5s;
    -moz-transition: box-shadow linear 0.5s,color linear 0.5s;    
    transition: box-shadow linear 0.5s,color linear 0.5s;
}
.hover:hover {
   box-shadow: inset 424px 0 0 0.09px #fff;
   color: #000;
}
<h1 class="hover">This is some really looong title!</h1>
like image 139
Zuriel Avatar answered Sep 20 '22 16:09

Zuriel