image moves on hover - chrome opacity issue

CssImageGoogle ChromeHoverOpacity

Css Problem Overview


There seems to be an issue with my page here: http://www.lonewulf.eu

When hovering over the thumbnails the image moves a bit on the right, and it only happens on Chrome.

My css:

.img{
	-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
	filter:alpha(opacity=50);
	-moz-opacity: 0.5; 
	opacity: 0.5;
	-khtml-opacity: 0.5;
	display:block;
	border:1px solid #121212;
}
.img:hover{
	-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
	filter:alpha(opacity=100);
	-moz-opacity: 1; 
	opacity: 1;
	-khtml-opacity: 1;	
	display:block;
}

Css Solutions


Solution 1 - Css

Another solution would be to use

-webkit-backface-visibility: hidden;

on the hover element that has the opacity. Backface-visibility relates to transform, so @Beskow's has got something to do with it. Since it is a webkit specific problem you only need to specify the backface-visibility for webkit. There are other vendor prefixes.

See http://css-tricks.com/almanac/properties/b/backface-visibility/ for more info.

Solution 2 - Css

For some reason Chrome interprets the position of elements without an opacity of 1 in a different way. If you apply the CSS attribute position:relative to your a.img elements there will be no more left/right movement as their opacity varies.

Solution 3 - Css

I had the same problem, I fixed it with css transform rotate. Like this:

-webkit-transform: rotate(0);
-moz-transform: rotate(0);
transform: rotate(0);

It works fine in major browsers.

Solution 4 - Css

Another solution that fixed this issue for me was to add the rule:

will-change: opacity;

In my particular case this avoided a similar pixel-jumping issue that translateZ(0) introduced in Internet Explorer, despite fixing things in Chrome.

Most of the other solutions suggested here that involve transforms (eg. translateZ(0), rotate(0), translate3d(0px,0px,0px), etc) work by handing painting of the element over to the GPU, allowing more efficient rendering. will-change provides a hint to the browser that has presumably a similar effect (allowing the browser to render the transition more efficiently), but feels less hacky (since it's explicitly addressing the problem rather than just nudging the browser to use the GPU).

Having said that, it's worth bearing in mind that browser support is not as good for will-change (though if the issue is with Chrome only then this might be a good thing!), and in some situations it can introduce problems of its own, but still, it's another possible solution to this issue.

Solution 5 - Css

I was need apply both backface-visibility and transform rules to prevent this glitch. Like this:

a     {-webkit-transform: rotate(0);}
a img {-webkit-backface-visibility: hidden;}

Solution 6 - Css

I had a similar issue with (non-opacity) filters on hover. Fixed by adding a rule to the base class with:

filter: brightness(1.01);

Solution 7 - Css

backface-visibility (or -webkit-backface-visibility) only fixed the issue in Chrome for me. To fix in both Firefox and Chrome I used the following combination of above answers.

//fixes image jiggle issue, please do not remove
img {
  -webkit-backface-visibility: hidden; //Webkit fix
  transform: translate3d(0px,0px,0px); //Firefox fix
}

Solution 8 - Css

I encountered a similar issue in Safari 8.0.2, where images would jitter as their opacity transitioned. None of the fixes posted here worked, however the following did:

-webkit-transform: translateZ(0);

All credit to this answer via this subsequent answer

Solution 9 - Css

Solution 10 - Css

The solution alpipego was served me in this problem. Use -webkit-backface-visibility: hidden; With this the image no move in hover opacity transition

/* fix error hover image opacity*/
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;

Solution 11 - Css

I had trouble with all the other solutions here, as they require changes to the CSS that may break other things -- position:relative requires me to completely rethink how I'm positioning my elements, transform:rotate(0) can interfere with existing transforms and gives wonky little transition effects when I have a transition-duration set, and backface-visibility won't work if I ever actually need a backface (and requires a whole lot of prefixing.)

The laziest solution I found is to just set an opacity on my element which is very close to, but not quite, 1. This is only a problem if opacity's 1, so it's not going to break or interfere with any of my other styles:

opacity:0.99999999;

Solution 12 - Css

Having marked Rick Giner's answer as correct I then found out it did not fix the issue.

In my case I have responsive width images contained within a max-width div. Once the site width crosses that max width the images move on hover (using css transform).

The fix in my case was to simply amend the max width to a multiple of three, three columns in this case, and it fixed it perfectly.

Solution 13 - Css

I noticed you had opacity included in your CSS. I had the same exact issue with Chrome (the image moving on hover) .. all I did was disable the opacity and it was solved, no more images moving.

.yourclass:hover {
  /* opacity: 0.6; */
}

Solution 14 - Css

Had the same issue, My fix was putting the class before the src in the img tab.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTasosView Question on Stackoverflow
Solution 1 - CssalpipegoView Answer on Stackoverflow
Solution 2 - CssRick GinerView Answer on Stackoverflow
Solution 3 - CssBeskowView Answer on Stackoverflow
Solution 4 - CssNick FView Answer on Stackoverflow
Solution 5 - CssjamlandView Answer on Stackoverflow
Solution 6 - CssJuan CasaresView Answer on Stackoverflow
Solution 7 - CssandersraView Answer on Stackoverflow
Solution 8 - CssJames FletcherView Answer on Stackoverflow
Solution 9 - Cssuser2125009View Answer on Stackoverflow
Solution 10 - CssLenin ZapataView Answer on Stackoverflow
Solution 11 - CssJosh from QaribouView Answer on Stackoverflow
Solution 12 - CsssidonaldsonView Answer on Stackoverflow
Solution 13 - CsscssninjaView Answer on Stackoverflow
Solution 14 - CssJust BrowsingView Answer on Stackoverflow