I want to make an image that's wrapped in an a
tag darken on hover. To do this I simply made the wrapping a
tag's background black and applied:
a:hover > img {
opacity: .8;
-webkit-transition: opacity .2s ease-out;
transition: opacity .2s ease-out;
}
to the image.
This works, but I get a weird 'jumpy' issue when image element containers have float: left;
or display: inline-block;
applied. This only occurs on some images.
You can see this happening here when you hover over the middle image: https://jsfiddle.net/4566a85t/
Would anyone know how I could prevent this?
My code is:
HTML
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
<div class="wrapper">
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTojc9ycyhwL6TnP_lEhQrTXy8Cjrs738WeDmnDOmIXGmR20NEJTw">
</a>
</div>
CSS
.wrapper {
width: 25%;
float: left;
}
a {
background: black;
display: block;
}
img {
width: 100%;
margin: 0;
}
a:hover > img {
opacity: .8;
-webkit-transition: opacity .2s ease-out;
transition: opacity .2s ease-out;
}
EDIT:
I tried using -webkit-filter: brightness(70%);
with no black background, but had the same issue. Seems to be the transition that's the problem.