网页特效栏目收集了最全最新的前端网页插件,包括最流行的jQuery,Bootstrap,Js,Css,Vue等主流特效插件。
这是一款使用纯css实现的星级评分控件效果,可以自定义符号。
1.为星级评分创建5个单选按钮。
<div class="rating effect">
<input type="radio" name="rating_stars" value="star_one" id="star_one" />
<label for="star_one" class="stars">One star</label>
<input type="radio" name="rating_stars" value="star_two" id="star_two" />
<label for="star_two" class="stars">Two stars</label>
<input type="radio" name="rating_stars" value="star_three" id="star_three" />
<label for="star_three" class="stars">Three stars</label>
<input type="radio" name="rating_stars" value="star_four" id="star_four" />
<label for="star_four" class="stars">Four stars</label>
<input type="radio" name="rating_stars" value="star_five" id="star_five" />
<label for="star_five" class="stars">Five stars</label>
</div>
2.添加星级评分的核心CSS样式。
.rating {
background: white;
border-radius: 25px;
padding: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: space-around;
width: 90%;
margin: 30px auto 0;
}
.rating input {
display: none;
}
.rating label {
font-size: 0;
}
.rating label.stars::before, .rating label.hearts::before {
content: '';
display: block;
width: 20px;
height: 20px;
cursor: pointer;
}
/* Hover effect */
.rating.effect input:checked + label ~ label.stars::before, .rating.effect:hover input:hover + label ~ label.stars::before {
background: url(icons/star-regular.svg) no-repeat center center;
background-size: 20px;
opacity: .3;
}
.rating.effect:hover input + label ~ label.stars::before {
background: url(icons/star-solid.svg) no-repeat center center;
background-size: 20px;
}
.rating.effect input:checked + label ~ label.hearts::before, .rating.effect:hover input:hover + label ~ label.hearts::before {
background: url(icons/heart-regular.svg) no-repeat center center;
background-size: 20px;
opacity: .3;
}
.rating.effect:hover input + label ~ label.hearts::before {
background: url(icons/heart-solid.svg) no-repeat center center;
background-size: 20px;
}
3.向星级评分控件添加自定义符号。
.rating label.stars::before {
background: url(icons/star-solid.svg) no-repeat center center;
background-size: 20px;
}
.rating label.hearts::before {
background: url(icons/heart-solid.svg) no-repeat center center;
background-size: 20px;
}
转载请注明来源:css动画星级评分控件效果代码
本文永久链接地址:https://www.moyouyouw.cn/code/800.html
郑重声明:本站所有主题/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除,谢谢!我们不承担任何技术及版权问题,且不对任何资源负法律责任。
已有 位小伙伴发表了看法
欢迎 你 发表评论