How can "Transition" in CSS not occur when the page is updated?

Asked

Viewed 152 times

0

I’ve been creating some transition in some projects and I ended up noticing that the transition occurs when the page is loaded or updated. I have this example where the transition is to occur only when I pass the mouse over to div, and it changes the color with a smoother transition, but the transition is applied also when the page is loaded.

div{
    background-color: red;
    width: 200px;
    height: 200px;
    transition: background-color 2s;
}

div:hover{
    background-color: black;
}
<div></div>

It looks like an opacity effect and then returns to normal color. This occurs only with the Chrome and Opera, because I tested on Firefox, Edge, IE11 and the effect does not happen in the stackoverflow I don’t think you’ll notice, you’ll have to create an html file, but is there any way to stop it from happening? either in code or in the browser?

  • I can’t say for sure, but this seems like Chrome’s arbitrary behavior... take a look at this question and look at my answer as you solved it. If it works for you. https://answall.com/questions/383494/css-functionand-different-dentro-da-tag-ou-em-arquivo-separado-css including tb I indicate resetting the machine, because maybe it could be hardware and memory management or whatever. Worth testing... here I tested with your code today and I had no problems worked normal as expected, only activates the traffic in :Hover and not in refresh

  • No, it worked should be normal of Chrome and it operates to happen that, but it affects the projects that we create, it shouldn’t occur that.

  • I only noticed this after the last Chrome update. But currently it does not happen to me anymore, at the time I solved with the answer I gave in the question of the link I commented above

  • It was supposed to be a yes upstairs I misspelled. I tested the code and the animation happens before the Hover, it was very similar to my problem and I tested here the problem was fixed but because it occurs is a bug even or not?

  • Young man, I marked as duplicate because the other answer/question seems to solve the problem as I suspected. Unfortunately I can’t tell you why this is happening.It may be your machine’s individual problem, or it may be general (I don’t believe it is) or it is browser version problem, which I believe is most likely, although I can’t say.... I can only tell you how to fix it, but I can’t tell you why this is happening...

  • 1

    There is more ok, the important thing is that you helped me and solved the problem thank hugocsi

Show 1 more comment

2 answers

-1

To work in the mentioned browsers.

div{
    background-color: red;
    width: 200px;
    height: 200px;
    webkit-transition: background-color 2s; /* Para Google 
    Chrome anterior a 26.0 e para Safari 3.0 ~ 6.0*/
    -moz-transition: background-color 2s; /*Para Mozilla 
     anterior 16.0 */
     -o-transition: background-color 2s; /* Para Opera 
     anterior 12.1 */
    transition: background-color 2s;
}

div:hover{
    background-color: black;
}
  • Has YEARS-OLD that it is no longer necessary to put browser prefix in the property Transition http://prntscr.com/nsihrp source https://caniuse.com/#search=Transition the problem is another...

  • The "Transition" property is already supported by the latest summer of Chrome and Opera, no prefix required. The transition occurs but before it occurs there is an opacity effect that was not to happen.

-1

Because there are many browsers, and each one with its specification, it is necessary to add these prefixes for a CSS style to work on all. So we have to:

-webkit-

(Chrome, Safari, latest versions of Opera.)

-moz-

(Firefox)

-o-

(Old versions of Opera)

-ms-

(Internet Explorer)

Mozilla Reference Link

  • Thanks colleague, but that’s not the problem the property "Transition" works in all browsers the problem is that when the page is updated the browser automatically adds opacity and then goes back to normal state.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.