简体   繁体   English

如何更改 Facebook Font Awesome 图标的颜色?

[英]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.我想更改 Font Awesome Facebook 图标的颜色。 If I do it with background-color :如果我用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.它在 Facebook 徽标的蓝色“背景”边缘添加了白色,这是我不想要的。

Is there a simple solution to color only the "f" in the icon so that the color around the edges stays transparent?是否有一个简单的解决方案来只为图标中的“f”着色,以便边缘周围的颜色保持透明?

The icon only consists of the part around the 'f', the 'f' itself and the part around the edges are transparent.图标仅由“f”周围的部分组成,“f”本身和边缘周围的部分是透明的。 Therefore you have to create a white part only under the 'f'.因此,您必须仅在“f”下创建一个白色部分。

It's possible with a combination of a linear-gradient , background-size and background-position .可以组合使用linear-gradientbackground-sizebackground-position With the gradient you create a white rectangle, that you can scale and position to only lay under the 'f'.使用渐变创建一个白色矩形,您可以缩放和定位它以仅位于“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>

Kindly update your question to not only be for facebook icon but all font-awesome Icons.请更新您的问题,不仅适用于 facebook 图标,还适用于所有字体真棒图标。

ie IE

How to style the background for font awesome icons如何设置字体真棒图标的背景样式

This was what I had before这是我以前的

字体真棒社交图标

Then I used然后我用

background-color: white !important;

I got我有

使用背景色后

I then used然后我用

    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;

And the results结果

背景图片

Expreriment with the background size to fit your Icons.使用背景大小进行实验以适合您的图标。

Happy coding 🙂快乐编码🙂

Use stacked icons.使用堆叠图标。

Stack the fab fa-facebook-f classes with white text over the fa fa-square classes with your desired background.将带有白色文本的fab fa-facebook-f类堆叠在具有所需背景的fa fa-square类上。

Re: https://fontawesome.com/v5.15/how-to-use/on-the-web/styling/stacking-icons回复: 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>

You can use this SVG instead which creates no such edges.您可以改用此 SVG,它不会创建这样的边缘。

 body { background-color: black; }
 <?xml version="1.0" encoding="utf-8"?> <!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 448 448" style="enable-background:new 0 0 448 448;" xml:space="preserve"> <style type="text/css"> .st0{fill:#FFFFFF;} </style> <rect x="125.2" y="39.5" class="st0" width="274" height="408.5"/> <path fill="blue" d="M448,24.7v398.5c0,13.7-11.1,24.7-24.7,24.7H309.1V274.5h58.2l8.7-67.6h-67v-43.2c0-19.6,5.4-32.9,33.5-32.9h35.8V70.3 c-6.2-0.8-27.4-2.7-52.2-2.7c-51.6,0-87,31.5-87,89.4v49.9h-58.4v67.6h58.4V448H24.7C11.1,448,0,436.9,0,423.3V24.7 C0,11.1,11.1,0,24.7,0h398.5C436.9,0,448,11.1,448,24.7z"/> </svg>

It should do the job, at least in Angular + SVG combination it does.它应该可以完成这项工作,至少在 Angular + SVG 组合中是这样。 SCSS code with changing color on hover for fab fa-behance icon. SCSS 代码在fab fa-behance图标悬停时更改颜色。

&:hover {
    svg {
      &.fa-facebook-f {
        path {
          transition: 1s;
          fill: #3b5998;
        }
      }
    }
 }

If you do not want the white outline, I would remove the background-color tag.如果您不想要白色轮廓,我会删除背景颜色标签。 Check out this fiddle看看这个小提琴

<link rel="stylesheet" 

HTML: HTML:

href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<div>
<i class="fas fa-ambulance"></i>
</div>

JS: JS:

.fa-ambulance {
  color: red;
  background-color: black;
  font-size:100px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM