gpt4 book ai didi

html - FontAwesome 5 - 多色图标

转载 作者:太空狗 更新时间:2023-10-29 14:50:26 24 4
gpt4 key购买 nike

FontAwesome 5提供数千个使用 SVG 构建的图标。这样,使用 fill 就可以很容易地为整个图标着色。但是如果我想使用多种颜色怎么办?例如,给定图标 Google ,我想像这样给它上色:

CSS multi color icon of Google

最佳答案

通过对颜色和两个图标使用渐变,我们可以实现这一点,但它仍然是一种hacky方式,您需要具体处理每种情况(图标 + 着色):

.fa-google path{
fill:url(#grad1);
}
.fa-google + .fa-google path{
fill:url(#grad2);
}
.icon {
display:inline-block;
position:relative;
}
.fa-google + .fa-google {
position:absolute;
left:0;
top:0;
clip-path: polygon(0% 0%,120% 0%,0% 75%);
}
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js" ></script>
<svg style="width:0;height:0;">
<defs>
<linearGradient id="grad1" x1="0%" y1="30%" x2="50%" y2="0%">
<stop offset="50%" stop-color="#34a853" />
<stop offset="50%" stop-color="#4285f4" />
</linearGradient>
<linearGradient id="grad2" x1="0%" y1="30%" x2="50%" y2="0%">
<stop offset="50%" stop-color="#fbbc05" />
<stop offset="50%" stop-color="#ea4335" />
</linearGradient>
</defs>
</svg>
<div class="icon">
<i class="fab fa-google fa-7x"></i>
<i class="fab fa-google fa-7x"></i>
</div>

我们还可以考虑对一个图标使用conic-gradient()。同样,它特定于这种特殊情况:

.fa-google {
background: conic-gradient(from -45deg, #ea4335 110deg, #4285f4 90deg 180deg, #34a853 180deg 270deg, #fbbc05 270deg) 73% 55%/150% 150% no-repeat;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">

<i class="fab fa-google fa-10x"></i>
<i class="fab fa-google fa-6x"></i>
<i class="fab fa-google fa-3x"></i>

Fontawesome Google icon multi color

以上内容并非适用于所有浏览器,因此您可以考虑多个 linear-gradient,如下所示:

.fa-google {
background:
linear-gradient(to bottom left,transparent 49%,#fbbc05 50%) 0 25%/48% 40%,
linear-gradient(to top left,transparent 49%,#fbbc05 50%) 0 75%/48% 40%,

linear-gradient(-40deg ,transparent 53%,#ea4335 54%),
linear-gradient( 45deg ,transparent 46%,#4285f4 48%),
#34a853;
background-repeat:no-repeat;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}

/*#fbbc05*/
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">

<i class="fab fa-google fa-10x"></i>
<i class="fab fa-google fa-6x"></i>
<i class="fab fa-google fa-3x"></i>

关于html - FontAwesome 5 - 多色图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52578726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com