我无法使用这些代码着色font-awesome5图标.我尝试了“填充”css属性来设置颜色,但它没有用.
<div class="container mt200 icons"> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="fas fa-microphone fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.</div> </div> </div> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="far fa-edit fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. </div> </div> </div> </div>
CSS代码:
.icons i { color: #2759AE; }
解决方法
Font Awesome 5使用svg作为图标,里面的路径设置为fill:currentColor,所以只需更改svg的颜色:
.icons svg { color:#2759AE; }
<script defer src="https://use.fontawesome.com/releases/v5.5.0/js/all.js"></script> <div class="container mt200 icons"> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="fas fa-microphone fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.</div> </div> </div> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="far fa-edit fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. </div> </div> </div> </div>
正如您在代码中看到的,当您加载JS版本时,i将替换为svg:
如果您使用的是CSS版本,可以将颜色应用于i.
.icons i { color:#2759AE; }
<link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"><div class="container mt200 icons"> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="fas fa-microphone fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.</div> </div> </div> <div class="col-md-3"> <div class="bggray2 text-center"> <i class="far fa-edit fa-5x"></i> <div class="title">LOREM</div> <div class="text">Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. </div> </div> </div> </div>
因此,为了确保它在所有情况下都能工作,只需使用两个选择器:
.icons i,.icons svg { color: #2759AE; }