使用下面提供的宽度定义的Font Awesome的星级评分在Chrome和Firefox上正常运行,但在Edge和IE上并没有。任何人都知道它会是什么?
Chrome和Firefox
Edge和IE
.star-rating {
display: inline-block;
position: relative;
line-height: 1;
}
.star-rating:before,
.star-rating:after {
content: "\f005\f005\f005\f005\f005";
display: block;
font-family: "FontAwesome";
font-size: 25px;
color: #ccc;
}
.star-rating:after {
color: gold;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.star-rating.s0:after {
width: 0%;
}
.star-rating.s1:after {
width: 10%;
}
.star-rating.s2:after {
width: 20%;
}
.star-rating.s3:after {
width: 30%;
}
.star-rating.s4:after {
width: 40%;
}
.star-rating.s5:after {
width: 50%;
}
.star-rating.s6:after {
width: 60%;
}
.star-rating.s7:after {
width: 70%;
}
.star-rating.s8:after {
width: 80%;
}
.star-rating.s9:after {
width: 90%;
}
.star-rating.s10:after {
width: 100%;
}

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span class="star-rating s7"></span>
&#13;
答案 0 :(得分:2)
这是bug that the M$ browser has when dealing with pseudo elements。解决方法是:
.star-rating {overflow: hidden;}
在符合标准的浏览器(例如Chrome和Firefox等真实浏览器)下,只需.star-rating::after
即可。不幸的是,M $浏览器是垃圾。
检查开发人员工具中的样式,您会发现所有伪元素::before
和::after
都已被删除。这是IE感染的众多错误之一。以下是症状:
问题:在OP的特定情况下,伪元素:
<小时/> 解决方法:将.star-rating::after
属性:overflow: hidden
被忽略,因为IE需要父代:.star-rating
拥有它。overflow: hidden
应用于.star-rating
.star-rating {
display: inline-block;
position: relative;
line-height: 1;
overflow: hidden;
}
.star-rating:before,
.star-rating:after {
content: "\f005\f005\f005\f005\f005";
display: block;
font-family: "FontAwesome";
font-size: 25px;
color: #ccc;
}
.star-rating:after {
color: gold;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.star-rating.s0:after {
width: 0%;
}
.star-rating.s1:after {
width: 10%;
}
.star-rating.s2:after {
width: 20%;
}
.star-rating.s3:after {
width: 30%;
}
.star-rating.s4:after {
width: 40%;
}
.star-rating.s5:after {
width: 50%;
}
.star-rating.s6:after {
width: 60%;
}
.star-rating.s7:after {
width: 70%;
}
.star-rating.s8:after {
width: 80%;
}
.star-rating.s9:after {
width: 90%;
}
.star-rating.s10:after {
width: 100%;
}
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span class="star-rating s7"></span>
&#13;
答案 1 :(得分:1)
将white-space:nowrap
添加到.star-rating::before, .star-rating::after
规则。
.star-rating {
display: inline-block;
position: relative;
line-height: 1;
}
.star-rating:before,
.star-rating:after {
content: "\f005\f005\f005\f005\f005";
display: block;
font-family: "FontAwesome";
font-size: 25px;
color: #ccc;
white-space:nowrap;
}
.star-rating:after {
color: gold;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.star-rating.s0:after {
width: 0%;
}
.star-rating.s1:after {
width: 10%;
}
.star-rating.s2:after {
width: 20%;
}
.star-rating.s3:after {
width: 30%;
}
.star-rating.s4:after {
width: 40%;
}
.star-rating.s5:after {
width: 50%;
}
.star-rating.s6:after {
width: 60%;
}
.star-rating.s7:after {
width: 70%;
}
.star-rating.s8:after {
width: 80%;
}
.star-rating.s9:after {
width: 90%;
}
.star-rating.s10:after {
width: 100%;
}
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span class="star-rating s7"></span>
&#13;