css - 带有 css 的 Font Awesome 图标上的多色

标签 css font-awesome

我升级了我的评级插件,使用 Font Awesome 图标代替图像。我在半星评级方面遇到问题,我无法替换 fa-star-half-o 图标上的白色。我想用类似于下面预期结果的灰色替换白色。

请帮忙

代码:

<div class="ratingbox"><i class="fa fa-star"></i><i class="fa fa-star">
</i><i class="fa fa-star-half-o"></i><i class="fa fa-star unrated"></i>
<i class="fa fa-star enlang unrated"></i></div>

i
{
  float:left
}
.ratingbox
{
    display: block;
    clear: both;
}
.fa-star-half-o,.fa-star
{
    color: #ffab00;
  
}
.rated{
    color: #ffab00;
    cursor: pointer;
}

.unrated{
    color: #757575;
    cursor: pointer;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ratingbox">
<i class="fa fa-star"></i><i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i><i class="fa fa-star unrated"></i><i class="fa fa-star enlang unrated"></i>
</div>

当前结果

enter image description here

预期结果

enter image description here

最佳答案

网页设计中一切皆有可能,但也许您设法使用了一些技巧:

i
{
  float:left;
  position: relative;
}
.ratingbox
{
    display: block;
    clear: both;
}
.fa-star-half-o,.fa-star
{
    color: #ffab00;
  
}
.rated{
    color: #ffab00;
    cursor: pointer;
}

.unrated{
    color: #757575;
    cursor: pointer;
}

.fa-star-half-empty:after, .fa-star-half-full:after, .fa-star-half-o:after {
    content: "\f123";
    transform: rotateY(-180deg);
    display: inline-block;
    left: 6px;
    position: absolute;
    top: 0;
    color: #757575;
    overflow: hidden;
    width: 8px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ratingbox">
<i class="fa fa-star"></i><i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i><i class="fa fa-star unrated"></i><i class="fa fa-star enlang unrated"></i>
</div>

注意:我只是将 fa-star-half-o 字符添加到 after 元素,我的意思是这个 content: "\f123"; 然后反转它 transform: rotateY(-180deg); 和半宽度和绝对位置你可以看到这里发生了什么:

.fa-star-half-empty:after, .fa-star-half-full:after, .fa-star-half-o:after {
    content: "\f123";
    transform: rotateY(-180deg);
    display: inline-block;
    left: 6px;
    position: absolute;
    top: 0;
    color: #757575;
    overflow: hidden;
    width: 8px;
}

它不干净但聊胜于无!

关于css - 带有 css 的 Font Awesome 图标上的多色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46619428/

相关文章:

javascript - 如何制作船舶动画

html - 为什么移动设备上的 Safari 需要很长时间才能从内存中加载图像?

fonts - Yosemite 上的 Font Awesome 4.2.0 TTF

html - 伪元素上的 Font Awesome 5 显示正方形而不是图标

html - 如何堆叠社交图标

html - 使用百分比后调整窗口大小时如何使元素停止移动

css - 占用整个页面,而不仅仅是窗口高度

php - 如何使用 ajax jquery 和 php 为多表单流程制作动画?

css - 图标(fontawesome, Material 图标)闪烁!/?问题

html - 试图将 Font Awesome 图标放在 div 的中间