【发布时间】:2019-10-21 15:20:00
【问题描述】:
我有这个 css 纯星级评分系统。
我想从中读取选定的值,并根据我的选择在右侧显示一条消息。
如何使用最小的 js 做到这一点?
.rating {
width: 208px;
height: 40px;
margin: 0 auto;
padding: 40px 50px;
border: 1px solid #CCCCCC;
background: #F9F9F9;
}
.rating label {
float: right;
position: relative;
width: 40px;
height: 40px;
cursor: pointer;
}
.rating label:not(:first-of-type) {
padding-right: 2px;
}
.rating label:before {
content: "\2605";
font-size: 42px;
color: #CCCCCC;
line-height: 1;
}
.rating input {
display: none;
}
.rating input:checked ~ label:before, .rating:not(:checked) > label:hover:before, .rating:not(:checked) > label:hover ~ label:before {
color: #F9DF4A;
}
<h5>Pure CSS Star Rating</h1>
<div class="rating">
<input type="radio" id="star5" name="rating" value="5" /><label for="star5"></label>
<input type="radio" id="star4" name="rating" value="4" /><label for="star4"></label>
<input type="radio" id="star3" name="rating" value="3" /><label for="star3"></label>
<input type="radio" id="star2" name="rating" value="2" /><label for="star2"></label>
<input type="radio" id="star1" name="rating" value="1" /><label for="star1"></label>
</div>
【问题讨论】:
标签: javascript html css