When I use padding in a css transition, webkit browsers (safari osx, Chrome osx & Chrome windows) have a little glitch at the start and the end of each transition, resulting in a 1px movement of elements placed after the animated element.
HTML
test test test <span class="test">Hover me</span> test test test test
CSS
.test{
color:#FFF;
background:#000;
padding:4px 4px 4px 30px;
transition: padding 0.5s linear;
}
.test:hover{
padding:4px 30px 4px 4px;
}
I've searched and tried various solutions, but nothing solves this example?!
CSS transition glitch
CSS transition effect makes image blurry / moves image 1px, in Chrome?
(Example filled with possible solutions: http://jsfiddle.net/QG4QV/18/ , but nothing works)
Best Answer
I do not know if there is another explanation for the glitch. I would guess that the animation of padding values is causing rounding inconsistencies during the transitioning which have an affect on the overall width of the
.test
element.I found that the following CSS fixes it for me in Chrome33.
Demo
Edit: So looking at the element in the Chrome DevTools, without
display:inline-block
the "Hover Me" text itself has awidth=auto
andheight=auto
computed style.With the
inline-block
the text has a computed style ofwidth=60
andheight=20
. I think it is this hard computed style that stops the transition glitching.