55

I'm having an issue in chrome with a css3 transform rotate transition. The transition is working fine but just after it finishes the element shifts by a pixel. The other strange thing is that it only happens when the page is centered (margin:0 auto;). The bug is still there if you remove the transition as well.

You can see it happening here:

http://jsfiddle.net/MfUMd/1/

HTML:

<div class="wrap">
    <img src="https://github.com/favicon.ico" class="target" alt="img"/>
</div>

<div class="wrap">
    <div class="block"></div>
</div>

CSS:

.wrap {
    margin:50px auto;
    width: 100px;
}
.block {
    width:30px;
    height:30px;
    background:black;
}
.target,.block {
    display:block;
    -webkit-transition: all 0.4s ease;
    -moz-transition: all 0.4s ease;
    -o-transition: all 0.4s ease;
    transition: all 0.4s ease;
}
.target:hover,.block:hover {
    -webkit-transform: rotate(90deg); 
    -moz-transform: rotate(90deg); 
    -o-transform: rotate(90deg);
    -ms-transform: rotate(90deg);  
}

Comment out the margin:0 auto; line to make it go away.

Anyone have any ideas of how to stop this while keeping the page centered?

I'm using Version 24.0.1312.57 on OSX 10.6.8

Cheers

JSuar
  • 21,056
  • 4
  • 39
  • 83
DonutReply
  • 3,184
  • 6
  • 31
  • 34

5 Answers5

108

Actually just add this to the site container which holds all the elements: -webkit-backface-visibility: hidden;

Should fix it!

Gino

Mooseman
  • 18,763
  • 14
  • 70
  • 93
Gino
  • 1,176
  • 1
  • 8
  • 7
22

I had the same issue, I fixed it by adding the following to the css of the div that is using the transition:

-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1.0, 1.0);

Backface is used for 3D-based transitions but if you are only using 2D there is no need for the extra stuff.

Delmontee
  • 1,898
  • 2
  • 26
  • 44
  • 1
    Thanks for the complement with `transform`, this answer solved my issue. – Alexis B. Oct 23 '15 at 12:20
  • Holy crap, this worked on a totally unrelated transform I was trying; but since you mentioned "3D based transitions", I gave it a shot. Lo and behold... Thanks! – taketheleap Dec 23 '15 at 15:15
  • @FredK: Just add it to your list of transform values. Adding `translateZ(0)` was enough in my case. – wortwart Jun 27 '16 at 15:02
2

will-change: transform; on the element helped to me in 2022 (Chrome). No more 1px shift of the text inside the element after zoom animation.

Vladimir Tolstikov
  • 2,463
  • 21
  • 14
0

there is something unusual in the relation between the body dimension and the structure of the transform. I don't in fact is because the fiddle iframe that contains the preview of the code.

Anyway, I will suggest this approach instead:

body{
  width:100%;
  float:left;
}

.wrap {
  margin: 50px 45%;
  width: 5%;
  float: left;
}
.block {
  width:30px;
  height:30px;
  background:black;
}
.target,.block {
  -webkit-transition: all 0.4s ease;
  -moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.target:hover,.block:hover {
-webkit-transform: rotate(90deg); 
    -moz-transform: rotate(90deg); 
    -o-transform: rotate(90deg);
    -ms-transform: rotate(90deg);  
}

Here is the updated fiddle

wandarkaf
  • 1,839
  • 20
  • 30
0

For 3d transform use this instead:

-webkit-transform: perspective(1px) scale3d(1.1, 1.1, 1);
transform: perspective(1px) scale3d(1.1, 1.1, 1);