【发布时间】:2022-01-07 13:34:06
【问题描述】:
我正在使用 ng-rating 来显示分数的平均值。问题是当平均值为 3.97 时。 Ng-rating 仍然显示为 3 星。我怎样才能让它像半颗星星一样显示? 我的html:
<div style="font-size: x-large; color: orange;"><ngb-rating [max]="5" [(rate)]="overallScore" [readonly]="false"></ngb-rating></div>
3.67 值的示例: star
编辑: 在尝试来自引导站点 4 的解决方案时 hearts 心塞有点方?
编辑2:
模板:
<ng-template #t let-fill="fill">
<span class="star" [class.full]="fill === 100">
<span class="half" [style.width.%]="fill">⭐</span>⭐
</span>
</ng-template>
我已将代码更改为 css
.star {
position: relative;
display: inline-block;
font-size: 3rem;
color: #d3d3d3;
}
.star.full {
color: #ffa600;
}
.star.half {
position: absolute;
display: inline-block;
overflow: hidden;
color: #ffa600;
}
它给出了结果: stars
【问题讨论】:
-
您可以包含其余代码吗?另外,请参阅本教程:ng-bootstrap.github.io/#/components/rating/examples#decimal
-
@ShaunLoftin 您的意思是根据给定数据计算平均值的代码吗?因为除了那个我没有任何代码。从您的链接尝试解决方案,但从它复制 1:1 后这里有一个小问题。
标签: javascript html twitter-bootstrap