如何在IE和Chrome中获得相同的结果(半星)。
在chrome:http://jsfiddle.net/Auqj8/
.star {
font-size: x-large;
width: 50px;
display: inline-block;
color: gray;
}
.star:last-child {
margin-right: 0;
}
.star:before {
content: '\2605';
}
.star.on {
color: gold;
}
.star.half:after {
content: '\2605';
color: gold;
margin-left: -20px;
width: 10px;
position: absolute;
overflow: hidden;
}
在IE中:http://jsfiddle.net/86pqx/
谢谢。
答案 0 :(得分:6)
这适用于chrome和IE
.star {
font-size: x-large;
width: 50px;
display: inline-block;
color: gray;
}
.star:last-child {
margin-right: 0;
}
.star:before {
content:'\2605';
}
.star.on {
color: gold;
}
.star.half:after {
content:'\2605';
color: gold;
position: absolute;
margin-left: -20px;
width: 10px;
overflow: hidden;
}
Chrome:http://jsfiddle.net/Auqj8/1/
答案 1 :(得分:0)
这是我的解决方法:
SCSS:
%full-star {
&:after {
content: "\f005";
}
};
%half-star {
&:after {
content: "\f123";
}
};
.rating {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: flex-start;
color: #900;
$this: &;
&__item {
font-size: 24px;
display: block;
font-family: FontAwesome;
&::after {
content: '\f006 ';
}
}
@for $i from 0 to 6 {
&[data-rating='#{$i}'] {
#{$this}__item:nth-child(-n + #{$i}) {
@extend %full-star;
}
}
&[data-rating='#{$i + 0.5}'] {
#{$this}__item:nth-child(-n + #{$i}) {
@extend %full-star;
}
#{$this}__item:nth-child(#{$i + 1}) {
@extend %half-star;
}
}
}
}
HTML:
<ul class="rating" data-rating="3.5">
<li class="rating__item"></li>
<li class="rating__item"></li>
<li class="rating__item"></li>
<li class="rating__item"></li>
<li class="rating__item"></li>
</ul>