我使用此处找到的代码用于多个CSS星级评分无线电:https://stackoverflow.com/a/27067571/2520920
.rating {
float: left;
}
.rating:not(:checked) > input {
position: absolute;
top: -9999px;
clip: rect(0, 0, 0, 0);
}
.rating:not(:checked) > label {
float: right;
width: 1em;
padding: 0 .1em;
overflow: hidden;
white-space: nowrap;
cursor: pointer;
font-size: 200%;
line-height: 1.2;
color: #ddd;
text-shadow: 1px 1px #bbb, 2px 2px #666, .1em .1em .2em rgba(0, 0, 0, .5);
}
.rating:not(:checked) > label:before {
content: ★
}
.rating > input:checked ~ label {
color: #ff7700;
text-shadow: 1px 1px #c60, 2px 2px #940, .1em .1em .2em rgba(0, 0, 0, .5);
}
.rating:not(:checked) > label:hover,
.rating:not(:checked) > label:hover ~ label {
color: gold;
text-shadow: 1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0, 0, 0, .5);
}
.rating> input:checked + label:hover,
.rating> input:checked + label:hover ~ label,
.rating> input:checked ~ label:hover,
.rating> input:checked ~ label:hover ~ label,
.rating> label:hover ~ input:checked ~ label {
color: #ea0;
text-shadow: 1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0, 0, 0, .5);
}
.rating > label:active {
position: relative;
top: 2px;
left: 2px;
}

<div class="control-group">
<label class="control-label" for="meals">Meals</label>
<div class="controls rating one">
<input type="radio" id="star5" name="meals" value="5" />
<label for="star5"><span>★</span>
</label>
<input type="radio" id="star4" name="meals" value="4" />
<label for="star4"><span>★</span>
</label>
<input type="radio" id="star3" name="meals" value="3" />
<label for="star3"><span>★</span>
</label>
<input type="radio" id="star2" name="meals" value="2" />
<label for="star2"><span>★</span>
</label>
<input type="radio" id="star1" name="meals" value="1" />
<label for="star1"><span>★</span>
</label>
</div>
</div>
<!--added so that you can see the page jump--->
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class="control-group">
<label class="control-label" for="lodging">Lodging</label>
<div class="controls rating two">
<input type="radio" id="star5-1" name="lodging" value="5" />
<label for="star5-1"><span>★</span>
</label>
<input type="radio" id="star4-1" name="lodging" value="4" />
<label for="star4-1"><span>★</span>
</label>
<input type="radio" id="star3-1" name="lodging" value="3" />
<label for="star3-1"><span>★</span>
</label>
<input type="radio" id="star2-1" name="lodging" value="2" />
<label for="star2-1"><span>★</span>
</label>
<input type="radio" id="star1-1" name="lodging" value="1" />
<label for="star1-1"><span>★</span>
</label>
</div>
</div>
<!--added so that you can see the page jump--->
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class="control-group">
<label class="control-label" for="trans">Transportation</label>
<div class="controls rating three">
<input type="radio" id="star5-2" name="trans" value="5" />
<label for="star5-2"><span>★</span>
</label>
<input type="radio" id="star4-2" name="trans" value="4" />
<label for="star4-2"><span>★</span>
</label>
<input type="radio" id="star3-2" name="trans" value="3" />
<label for="star3-2"><span>★</span>
</label>
<input type="radio" id="star2-2" name="trans" value="2" />
<label for="star2-2"><span>★</span>
</label>
<input type="radio" id="star1-2" name="trans" value="1" />
<label for="star1-1"><span>★</span>
</label>
</div>
</div>
&#13;
每次点击星级评分,页面都会跳到顶部。我已经使用.rating > label:active
CSS属性玩了很多 - 我可以让页面保持不动但星级评分不起作用。
非常感谢任何建议。谢谢!
答案 0 :(得分:0)
从绝对位置确定您的位置。
这里
.rating:not(:checked) > input {
position: fixed;
top: -9999px;
clip: rect(0, 0, 0, 0);
}