如何为没有边框的图标添加渐变颜色
How to add a gradient color to an icon with no border
我想制作一个喜欢的图标,我想在悬停时用渐变色完全填充一个图标,没有边框只有心形。我用 fontawesome.
html:
<i class="far fa-heart"></i>
sass:
i{
position: absolute;
left: 70vmin;
top:2vmin;
font-size: 1.6em;
z-index: 100;
cursor: pointer;
font-weight: 100;
&:hover{
transition: all .8s ease-in-out;
-webkit-background-clip: text;
font-weight: 900;
background-image: linear-gradient($color-primary, $color-secondary);
-webkit-text-fill-color: transparent;
}
我看到很多人用background-clip 和text-fill-color 只是图标不见了。
有什么解决办法吗?
谢谢
你可以这样实现:
i{
position: absolute;
left: 70vmin;
top:2vmin;
font-size: 1.6em;
z-index: 100;
cursor: pointer;
font-weight: 100;
}
i:hover:before{
transition: all .8s ease-in-out;
-webkit-background-clip: text;
font-weight: 900;
background-image: linear-gradient(red, yellow);
-webkit-text-fill-color: transparent;
}
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<i class="far fa-heart"></i>
我想制作一个喜欢的图标,我想在悬停时用渐变色完全填充一个图标,没有边框只有心形。我用 fontawesome.
html:
<i class="far fa-heart"></i>
sass:
i{
position: absolute;
left: 70vmin;
top:2vmin;
font-size: 1.6em;
z-index: 100;
cursor: pointer;
font-weight: 100;
&:hover{
transition: all .8s ease-in-out;
-webkit-background-clip: text;
font-weight: 900;
background-image: linear-gradient($color-primary, $color-secondary);
-webkit-text-fill-color: transparent;
}
我看到很多人用background-clip 和text-fill-color 只是图标不见了。
有什么解决办法吗?
谢谢
你可以这样实现:
i{
position: absolute;
left: 70vmin;
top:2vmin;
font-size: 1.6em;
z-index: 100;
cursor: pointer;
font-weight: 100;
}
i:hover:before{
transition: all .8s ease-in-out;
-webkit-background-clip: text;
font-weight: 900;
background-image: linear-gradient(red, yellow);
-webkit-text-fill-color: transparent;
}
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<i class="far fa-heart"></i>