【发布时间】:2019-01-02 09:01:57
【问题描述】:
我已经实施了星级评定,效果很好。现在的要求是为每个星星设置不同的颜色,其中我的星星颜色来自 CSS,其颜色为 GOLD。我怎样才能给它不同的颜色。例如 - 第一颗星应该是红色,第二颗蓝色,第三颗绿色等等..
<fieldset class="rating">
<ng-container *ngFor="let star of starList">
<input type="radio" id="th {{star.id}} {{j}}" name="th_{{j}}" (click)="updateRating(star.value,kpi.kpiId)" />
<label [class]="star.class" for="th {{star.id}} {{j}}" [title]="star.value"></label>
</ng-container>
</fieldset>
CSS:
.rating {
border: none;
float: left;
direction: ltr;
}
.rating>input {
display: none;
}
.rating>label:before {
margin: 5px;
font-size: 1.25em;
font-family: "Font Awesome 5 Free";
display: inline-block;
content: "\f005";
font-weight: 900;
}
.rating>.half:before {
content: "\f089";
position: absolute;
}
.rating>label {
color: #ddd;
float: right;
}
.rating>input:checked~label,
/* show gold star when clicked */
.rating:not(:checked)>label:hover,
/* hover current star */
.rating:not(:checked)>label:hover~label {
color: gold;
cursor: pointer;
}
【问题讨论】:
-
请将相应的代码添加到问题中,作为您所拥有的工作示例,这有助于 SO 社区更好地回答您的问题。 Minimal, Complete, and Verifiable example
-
使类名也像class1,class2,class3一样动态化..并为每个类赋予样式
-
我也更新了css。请先生看看。