How to change the color of an image on hover
Ideally you should use a transparent PNG with the circle in white and the background of the image transparent. Then you can set the background-color
of the .fb-icon
to blue on hover. So you're CSS would be:
fb-icon{
background:none;
}
fb-icon:hover{
background:#0000ff;
}
Additionally, if you don't want to use PNG's you can also use a sprite and alter the background position. A sprite is one large image with a collection of smaller images which can be used as a background image by changing the background position. So for eg, if your original circle image with the white background is 100px X 100px, you can increase the height of the image to 100px X 200px, so that the top half is the original image with the white background, while the lower half is the new image with the blue background. Then you set setup your CSS as:
fb-icon{
background:url('path/to/image/image.png') no-repeat 0 0;
}
fb-icon:hover{
background:url('path/to/image/image.png') no-repeat 0 -100px;
}
If the icon is from Font Awesome (https://fontawesome.com/icons/) then you could tap into the color css property to change it's background.
fb-icon{
color:none;
}
fb-icon:hover{
color:#0000ff;
}
This is irrespective of the color it had. So you could use an entirely different color in its usual state and define another in its active state.
It's a bit late but I came across this post.
It's not perfect but here's what I do.
HTML Code
<div class="showcase-menu-social"><img class="margin-left-20" src="images/graphics/facebook-50x50.png" alt="facebook-50x50" width="50" height="50" /><img class="margin-left-20" src="images/graphics/twitter-50x50.png" alt="twitter-50x50" width="50" height="50" /><img class="margin-left-20" src="images/graphics/youtube-50x50.png" alt="youtube-50x50" width="50" height="50" /></div>
CSS Code
.showcase-menu {
margin-left:20px;
margin-right:20px;
padding: 0px 20px 0px 20px;
background-color: #C37500;
behavior: url(/css/border-radius.htc);
border-radius: 20px;
}
.showcase-menu-social img:hover {
background-color: #C37500;
opacity:0.7 !important;
filter:alpha(opacity=70) !important; /* For IE8 and earlier */
box-shadow: 0 0 0px #000000 !important;
}
Now my border radius of 20px matches up exactly with the image border radius. As you can see the .showcase-menu has the same background as the .showcase-menu-social. What this does is to allow the 'opacity' to take effect and no 'square' background or border shows, thus the image slightly reduces it's saturation on hover.
It's a nice effect and does give the viewer the feedback that the image is in focus. I'm fairly sure on a darker background, it would have even a better effect.
The nice thing is that this is valid HTML-CSS code and will validate. To be honest, it should work on non-image elements just as good as images.
Enjoy!
An alternative solution would be to use the new CSS mask image functionality which works in everything apart from IE (still not supported in IE11). This would be more versatile and maintainable than some of the other solutions suggested here. You could also more generally use SVG. e.g.
item { mask: url('/mask-image.png'); }
There is an example of using a mask image here:
http://codepen.io/zerostyle/pen/tHimv
and lots of examples here:
http://codepen.io/yoksel/full/fsdbu/