代码之家  ›  专栏  ›  技术社区  ›  Haradzieniec

更改字体图标的颜色

  •  1
  • Haradzieniec  · 技术社区  · 6 年前

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

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

    字体版本是:4.7.0。

    2 回复  |  直到 6 年前
        1
  •  6
  •   Temani Afif BoltClock    6 年前

    这个图标的感叹号是一个透明的部分,所以一个技巧是在它后面添加一个背景以获得所需的颜色。当然,背景不应该覆盖整个区域,所以我们需要用梯度来覆盖它的一部分。

    .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>

    .fa感叹号三角形{
    background:linear-gradient(红色,红色)中底/20%84%无重复;
    <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>
        2
  •  2
  •   Temani Afif BoltClock    6 年前

    答案 Temani Afif

    .fa-exclamation-triangle{
      position: relative;
      z-index:0;
    }
    .fa-exclamation-triangle:after{
      content: ' ';
      width: 20%;
      height: 70%;
      position: absolute;
      top: 15%;
      left: 40%;
      background: red;
      z-index: -1;
    }
    <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>