我试图在http://fortawesome.github.io/Font-Awesome/examples/
改变星级评分中前两颗星的颜色我已经为第一个和第一个分配了一个班级。第二个跨度,但它无法正常工作
我的HTML是
<span class="rating">
<span class="star filled"></span>
<span class="star filled"></span>
<span class="star"></span>
<span class="star"></span>
<span class="star"></span>
</span>
我的css是
.rating {
unicode-bidi:bidi-override;
direction:rtl;
font-size:30px;
}
.rating span.star {
font-family:FontAwesome;
font-weight:normal;
font-style:normal;
display:inline-block;
}
.rating span.star:hover {
cursor:pointer;
}
.rating span.star:before {
content:"\f006";
padding-right:5px;
color:#999999;
}
.rating span.star:hover:before, .rating span.star:hover~span.star:before {
content:"\f005";
color:#e3cf7a;
}
.filled{ color:#e3cf7a; }
答案 0 :(得分:3)
.filled
不够具体,请使用span.star.filled
:before
设置的,因此请使用span.star.filled:before{ color:#e3cf7a; }
content:"\f005";
。但这可能仍然不是你想要的;您可能没有注意到,但.rating
类会更改文字方向(unicode-bidi:bidi-override; direction:rtl;
)。
因此,您需要将filled
类应用于最后两个span标记。
答案 1 :(得分:3)
试一下这个
的 Jsfiddle 强>
脚本:
$('.rating span.star').click(function(){
var total=$(this).parent().children().length;
var clickedIndex=$(this).index();
$('.rating span.star').removeClass('filled');
for(var i=clickedIndex;i<total;i++){
$('.rating span.star').eq(i).addClass('filled');
}
});
答案 2 :(得分:0)
.rating{unicode-bidi:bidi-override;direction:rtl;font-size:10px;} .rating span.star{font-family:FontAwesome;font-weight:normal;font-style:normal;display:inline-block} .rating span.star:hover{cursor:pointer} .rating span.star:before{content:"\f006";padding-right:5px;color:#999} .rating span.star:hover:before,.rating span.star:hover~span.star:before{content:"\f005";color:#e3cf7a} .rating span.star.filled {} .rating span.star.filled:before{content:"\f005";color:#e3cf7a; }
<span class="rating" style="font-size:13px;"><span class="star"></span><span class="star"></span><span class="star filled"></span><spanclass="star filled"></span><span class="star filled"></span></span>