当前位置: 首页 > 面试题库 >

更改Font Awesome图标的颜色

金英华
2023-03-14
问题内容

如何更改图标的内部(白色)颜色 <i class="fa fa-exclamation-triangle"></i>

PS应用<i class="fa fa-exclamation-triangle" style="color:red"></i>不是答案,因为红色适用于外部颜色,而不适用于内部感叹号白色标牌本身。

真棒字体版本是:4.7.0。


问题答案:

此图标的感叹号是透明的部分,因此一个技巧是在其后面添加背景以具有所需的颜色。当然,背景不应该覆盖整个区域,因此我们需要使用渐变来覆盖其中的一部分。

.fa-exclamation-triangle {

  background:linear-gradient(red,red) center bottom/20% 84% no-repeat;

}


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">

<i class="fas fa-exclamation-triangle fa-7x"></i>

<i class="fas fa-exclamation-triangle fa-4x"></i>

<i class="fas fa-exclamation-triangle fa-2x"></i>

V4也是如此:

.fa-exclamation-triangle {

  background:linear-gradient(red,red) center /20% 70% no-repeat;

}


<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<i class="fa fa-exclamation-triangle fa-5x"></i>

<i class="fa fa-exclamation-triangle fa-4x"></i>

<i class="fa fa-exclamation-triangle fa-2x"></i>

也是SVG版本:

.fa-exclamation-triangle {

  background:linear-gradient(red,red) center bottom/20% 84% no-repeat;

}


<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js" ></script>

<i class="fas fa-exclamation-triangle fa-7x"></i>

<i class="fas fa-exclamation-triangle fa-4x"></i>

<i class="fas fa-exclamation-triangle fa-2x"></i>

更新

为了使答案更通用,我们还可以考虑多个背景和径向渐变,以便为任何形状着色。诀窍是在背景上覆盖透明部分而不会溢出。

这是一些图标示例:

.fa-exclamation-triangle {

  background:linear-gradient(red,red) center bottom/20% 84% no-repeat;

}

.fa-ambulance {

 background:

  linear-gradient(blue,blue) 25% 30%/32% 45% no-repeat,

  radial-gradient(green 60%,transparent 60%) 15% 100%/30% 30% no-repeat,

  radial-gradient(green 60%,transparent 60%) 85% 100%/30% 30% no-repeat;

}

.fa-check-circle {

  background:radial-gradient(yellow 60%,transparent 60%);

}

.fa-angry {

 background:

  radial-gradient(red 60%,transparent 60%) 25% 40%/30% 30% no-repeat,

  radial-gradient(red 60%,transparent 60%) 75% 40%/30% 30% no-repeat;

}


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">

<i class="fas fa-exclamation-triangle fa-7x"></i>

<i class="fas fa-ambulance fa-7x"></i>

<i class="fas fa-check-circle fa-7x"></i>

<i class="fas fa-angry fa-7x"></i>


 类似资料:
  • 我创建了一个包含单个项目的菜单。 这是我在工具栏中的一些活动中使用的,单击时它会下拉一个菜单,目前只有一个选项,但将来可能会更多。 除了图标外,一切都很好,它是传统3点白色的矢量图像。根据showAsAction在更改颜色时的设置。 目前show AsAction设置为从不,因此单击时会显示一个菜单,这就是我想要的,但是图标变为深灰色。如果我将此选项设置为“始终”,则图标变为白色,但我丢失了下拉菜

  • 如何更改UIkit图标的颜色。我正在使用react组件。具体地说,我想改变分隔图标的颜色:https://getuikit.com/docs/divider 谢了。

  • 我已经在我的应用程序上集成了底部栏导航栏。但是当我刷的时候,Tab的颜色不会改变。很奇怪因为我有选择器文件。有什么解决这个问题的主意吗?

  • 我添加到产品的愿望列表中。(django项目)如果用户将一个产品添加到这个列表中,就点击一个心形图标。如果用户已经将此产品添加到列表中,则心图标为红色,如果此产品不在用户收藏夹列表中,则心图标为白色。每次移除或将图标添加到列表中时,我都想更改图标的颜色。在我写的代码中,这个操作只做一次,如果它同时再次点击,颜色不会有任何变化。

  • 我通过图像视图显示了程序中的图标。按下按钮时,黄色图标应变为红色。我尝试了所有方法,但没有一个有效。...背景颜色...他把图像视图变成红色,呈全正方形。我只想让图标改变颜色。这是非常困难的'请帮忙。谢谢。 我的代码:

  • 我如何从FontAwesome的图标中设计图标的颜色、大小和阴影? 例如,FontAw的网站将显示一些白色图标和一些红色图标,但不会显示CSS以了解如何以这种方式设置它们的样式……