Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the color of the Facebook Font Awesome icon?

I would like to change the color of the Font Awesome Facebook icon. If I do it with background-color:

body {
  font-size: 5em;
  background: #555
}

.fa-facebook-square {
  color: blue;
  background-color: #fff;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<i class="fa fa-facebook-square"></i>

It adds white around the edges of the blue 'background' of the Facebook logo, which I don't want.

Is there a simple solution to color only the "f" in the icon so that the color around the edges stays transparent?

like image 382
sir-haver Avatar asked Aug 15 '18 16:08

sir-haver


People also ask

How do you change the color of Font Awesome icons?

To change the color of the icons, simply add or change the “color” property in the CSS. So to change the color of the icons to red in the above example, add “color:red” to the .

Can I modify Font Awesome icons?

Select the SVG of font-awesome located in your extracted zip inside fonts. Repeat the procces uploading your own svg files. Inside Home (at the header of the page) Select the icons you want to download, customize them to give your custom names and select publish to have a link or download the fonts and css.

How can I change the color of my icons?

To change the color of an icon, select the icon you'd like to edit. The Format tab will appear. Then click Graphics Fill and select a color from the drop-down menu. To add an outline to your icon, click Shape Outline and select a color from the drop-down menu.


3 Answers

The icon only consists of the part around the 'f', the 'f' itself and the part around the edges are transparent. Therefore you have to create a white part only under the 'f'.

It's possible with a combination of a linear-gradient, background-size and background-position. With the gradient you create a white rectangle, that you can scale and position to only lay under the 'f'.

By using a relative unit (%), your white background rectangle scales with the corresponding font size.

body {
  font-size: 5em;
  background: #000
}

.fa-facebook-square {
  color: #3b5998;
  background-image: linear-gradient( to bottom, transparent 20%, white 20%, white 93%, transparent 93% );
  background-size: 55%;
  background-position: 70% 0;
  background-repeat: no-repeat;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<i class="fa fa-facebook-square"></i>
like image 153
andreas Avatar answered Oct 04 '22 01:10

andreas


Here are the basic icon default display outcomes:

Font awesome social icons

If you use:

background-color: white !important;

Then you get this:

After using background color

If you then use:

background-image: linear-gradient( to bottom, transparent 20%, white 20%, white 93%, transparent 93% );
background-size: 84%;
background-position: 60% 0;
background-repeat: no-repeat;

Then the result is:

background image

Experiment with the background-size to fit your icons.

like image 33
james ace Avatar answered Oct 04 '22 01:10

james ace


Use stacked icons.

Stack the fab fa-facebook-f classes with white text over the fa fa-square classes with your desired background.

Re: https://fontawesome.com/v5.15/how-to-use/on-the-web/styling/stacking-icons

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"/>
<span class="fa-stack fa-2x">
    <i style="color: blue;" class="fas fa-square fa-stack-2x"></i>
    <i style="color: white;" class="fab fa-facebook-f fa-stack-1x"></i>
</span>
like image 25
Josh_damian Avatar answered Oct 04 '22 02:10

Josh_damian