How can I make an image white on hover using CSS filters and transitions?
.uni-im img {
filter: brightness(0) invert(1);
}
I have added a transition property for a smooth effect:
.uni-im img {
filter: brightness(0) invert(1);
transition: filter .15s linear;
}
However, the transition affects both the brightness and invert properties simultaneously. Is there a way to make it turn white directly without passing through black?
Is this achievable with pure CSS?
Here's an example of what I'm trying to achieve:
div {
background: white;
border: 1px solid #ccc;
padding: 20px;
display: inline-block;
transition: background 2s linear;
}
img {
width: 30px;
height: 30px;
transition: filter 2s linear;
}
div:hover {
background: #3F85CE;
}
div:hover img {
filter: brightness(0) invert(1);
}
<div>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA3WAAAN1gGQb3mcAAAAB3RJTUUH4gsGEwwX9OWpBgAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTFH80I3AAAC00lEQVR4Xu2Z3UrEMBCFqyirq/iHLKggeCe6CuKFPzeuLIpXXqh4Iejb+Hq+ks7USZ3NJmltNqWrpxDczaYz53ydpGnNMhwgAAIgAAIgAAIgAAIgAAIgAAIgAAIgAAKlBJau3j8+29hI+VKp+pgBbTTt0hTjMXiuSZYsQWT...