0

This question is pretty basic, but I want to be sure there isn't an alternative method than what I currently do. Let's say I have a Facebook icon. As of now, when a user hovers over that image, I display a different image in order to change the color. Is there an alternative CSS method to doing this, so I am not using multiple images?

In the fiddle below, I tried changing the background, but that just covers the entire image.

.social-icon {
    width: 20px;
    height: 20px;
    transition: ease .3s;
    -webkit-transition: ease .3s;
    margin-right: 5px;
    cursor: pointer;
}
#facebook-icon {
    background-image: url(https://s3.us-east-2.amazonaws.com/optimumdesigns/facebook-logo-gray.png);
    background-size: 20px 20px;
}
#facebook-icon:hover {
  background: #FFF;
}
<div class="social-icon" id="facebook-icon"></div>

jsFiddle

Paul
  • 3,348
  • 5
  • 32
  • 76

2 Answers2

0

If you use the Font Awesome Facebook icon, you can change of the color of it in the CSS that way.

#facebook-icon {
  color: grey;
}

#facebook-icon:hover {
  color: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="social-icon" id="facebook-icon"><i class="fa fa-facebook"></i></div>
Kevin
  • 352
  • 2
  • 4
  • 13
  • Thanks for the suggestion. I am looking to do this in an efficient manner (not having to make an external request). – Paul Nov 14 '17 at 05:17
0

Try this:

#facebook-icon:hover {
    background-color: blue;
    background-image: url(https://s3.us-east-2.amazonaws.com/optimumdesigns/facebook-logo-gray.png);  
}

.social-icon {
    width: 20px;
    height: 20px;
    transition: ease .3s;
    -webkit-transition: ease .3s;        
    margin-right: 5px;
    cursor: pointer;
}

#facebook-icon {
    background-image: url(https://s3.us-east-2.amazonaws.com/optimumdesigns/facebook-logo-gray.png);
    background-size: 20px 20px;
}

#facebook-icon:hover {
    background-color: blue;
    background-image: url(https://s3.us-east-2.amazonaws.com/optimumdesigns/facebook-logo-gray.png);  
}
<div class="social-icon" id="facebook-icon"></div>
Kevin
  • 352
  • 2
  • 4
  • 13
Regis
  • 55
  • 6