当我点击两个最高收视率时,有人可以解释为什么这个css星级评分消失?我正在使用Chrome并从此处获取代码:http://code.stephenmorley.org/html-and-css/star-rating-widget/。
/*code from http://code.stephenmorley.org/html-and-css/star-rating-widget/*/
.starRating:not(old) {
display: inline-block;
width: 7.5em;
height: 1.5em;
overflow: hidden;
vertical-align: bottom;
}
.starRating:not(old)>input {
margin-right: -100%;
opacity: 0;
}
.starRating:not(old)>label {
display: block;
float: right;
position: relative;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path fill='#fff' stroke='#ccc' d='M 12,2.5 14.4,9.5 21.5,9.5 15.8,13.75 18.5,21.5 12,16.625 5.5,21.5 8.2,13.75 2.5,9.5 9.6,9.5 z'/></svg>");
background-size: contain;
}
.starRating:not(old)>label:before {
content: '';
display: block;
width: 1.5em;
height: 1.5em;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path fill='#9c3' stroke='#682' d='M 12,2.5 14.4,9.5 21.5,9.5 15.8,13.75 18.5,21.5 12,16.625 5.5,21.5 8.2,13.75 2.5,9.5 9.6,9.5 z'/></svg>");
background-size: contain;
opacity: 0;
transition: opacity 0.2s linear;
}
.starRating:not(old)>label:hover:before,
.starRating:not(old)>label:hover~label:before,
.starRating:not(:hover)> :checked~label:before {
opacity: 1;
}
.ratingdiv {
width: 100%;
text-align: center;
background-color: #DCDFE6;
}
&#13;
<div class="ratingdiv"><br /><br />
<span class="starRating">
<input id="rating5" type="radio" name="<?php echo $name; ?>" value="5">
<label for="rating5" title="outstanding!">5</label>
<input id="rating4" type="radio" name="<?php echo $name; ?>" value="4">
<label for="rating4" title="good!">4</label>
<input id="rating3" type="radio" name="<?php echo $name; ?>" value="3">
<label for="rating3" title="ok">3</label>
<input id="rating2" type="radio" name="<?php echo $name; ?>" value="2">
<label for="rating2" title="meh">2</label>
<input id="rating1" type="radio" name="<?php echo $name; ?>" value="1">
<label for="rating1" title="yuck!">1</label>
</span><br /></div>
&#13;
答案 0 :(得分:1)
你的风格margin-right: -100%;
搞砸了,当你点击最后的2时,你并没有真正点击你的想法。
要解决此问题,只需删除此样式,然后为input
设置position: absolute;
样式,这样它们就不会占用DOM中的空间。
.starRating:not(old) > input{
/*margin-right: -100%; Remove This*/
position: absolute; /*Add this*/
opacity : 0;
}