Bootstrap Boostrap ngb-评级半星星

ghg1uchk  于 2023-04-09  发布在  Bootstrap
关注(0)|答案(2)|浏览(195)

我使用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

dzjeubhm

dzjeubhm1#

对于带有小数的自定义模板,您可以使用以下内容:

<ng-template #scoreTemplate let-fill="fill">
    <span class="star" [class.full]="fill === 100">
      <span class="half" [style.width.%]="fill">⭐</span>⭐
    </span>
</ng-template>

<ngb-rating max="5"
  [(rate)]="overallScore"
  [readonly]="true"
  [starTemplate]="scoreTemplate">
</ngb-rating>

但你也需要样式:

.star {
  position: relative;
  display: inline-block;
  font-size: 3rem;
  color: #d3d3d3;

  &.full {
    color: #ffa600;
  }

  &.half {
    position: absolute;
    display: inline-block;
    overflow: hidden;
    color: #ffa600;
  }
}

对于只有半颗星星而不是所有小数,您可以用途:

<ng-template #scoreTemplate let-fill="fill">
    <span class="star" [class.full]="fill < 50">
      <span class="half" [style.width.%]="fill >= 50 ? 50 : 0">⭐</span>⭐
    </span>
</ng-template>

此外,您可以使用自定义图标替换emoji。

vlf7wbxs

vlf7wbxs2#

联系我们

<ngb-rating [max]="5"[(rate)]="overallScore" [readonly]="false">
    <ng-template let-fill="fill">
       <span class="star" [class.full]="fill===100"><span class="half"[tyle.width.%]="fill">&#9733;</span>&#9733;</span>
    </ng-template>
</ngb-rating>

样式页面

.star {
   height: 50px;
  position: relative;
  display: inline-block;
  font-size: 3rem;
  padding-top:5px;
  color: #d3d3d3;

  }

 .full {
   color: #ffa600;
  }
.starClass{
   position: absolute;
   display: inline-block;
   bottom: 30%;
   padding-top:4px;
   height:35px;
   color: #ffa600;
   overflow: hidden;

}

相关问题