当使用优秀的 Font Awesome 时,如何使图标不透明 - 比如我想使用 http://fortawesome.github.io/Font-Awesome/icon/chevron-circle-up/,但不希望黑色圆圈中的“向上箭头”是透明的,而是实心颜色(白色)?
谢谢!
当使用优秀的 Font Awesome 时,如何使图标不透明 - 比如我想使用 http://fortawesome.github.io/Font-Awesome/icon/chevron-circle-up/,但不希望黑色圆圈中的“向上箭头”是透明的,而是实心颜色(白色)?
谢谢!
更新:
正如xavier在下面指出的那样,font-awesome有堆叠图标,可以让您在不使用hack的情况下在图标后面放置一个圆形。基本上,您可以将想要的任何图标放在他们的fa-circle
图标之上。然后,您可以独立地为圆形设置样式,并将其更改为任何您喜欢的颜色。
这是一个基于他们网站代码的示例:
.fa-circle {
color: black;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"/>
<span class="fa-stack" style="vertical-align: top;">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fas fa-chevron-up fa-stack-1x fa-inverse"></i>
</span>
<i class="fa fa-chevron-circle-up"></i>
然后在你的CSS中:
.fa-chevron-circle-up {
background: yellow;
border-radius: 50%;
height: 1em;
width: 1em;
}
如果背景圆圈偏移了图标,你可以使用 line-height
属性来修复它。
你可以使用fa-stack,将fa-circle图标放在其他图标下面,以更好地控制边框周围的像素:
<span class="fa-stack">
<i class="fa fa-circle fa-stack-1x icon-a"></i>
<i class="fa fa-times-circle fa-stack-1x icon-b"></i>
</span>
使用:
.icon-a {
color: #FFF;
font-size: 0.9em;
}
.icon-b {
color: #000;
}
<i aria-hidden="true" class="fa fa-arrow-alt-circle-up fa-3x"></i>
CSS:
.fa{
color: red;
background: radial-gradient(grey 50%, transparent 50%);
}
如果您还感兴趣,我有另一条技巧:
<i class="fa fa-chevron-circle-up fa_with_bg"></i>
以下是CSS代码:
.fa_with_bg{
position: relative;
}
.fa_with_bg::after{
position: absolute;
content: '';
background: #fff;
z-index: -1;
top: 10px;
left: 3px;
width: 35px;
height: 33px;
}
您只需要为其添加 fa_with_bg
类即可。
* 您可能需要对 top
、left
、width
和 height
属性进行微调。
::before
阴影元素添加了position: relative; z-index: 1;
,并给::after
元素添加了一个z-index
值为0
。 - Jacob van Lingen我刚刚在字体Awesome链接中使用了一个样式,像这样...
<i class="fa fa-ban icon" style="background:#8BAAAD"></i>
// Note: Change background color to match your criteria
// SCSS
.fa-bg-white {
position: relative;
&:before {
position: relative;
z-index: 1;
}
&:after {
position: absolute;
content: '';
background: #FFF;
border-radius: 50%;
z-index: 0;
top: 10%;
left: 10%;
width: 75%;
height: 75%;
}
}
// HTML
<i class="fa fa-plus-circle fa-bg-white"></i>