纯CSS写评分

博客转载自https://www.cnblogs.com/hesj/p/10536792.html,介绍了纯CSS写评分用到的知识,如E:checked用于单选或复选框选中,E ~ F选择后面兄弟节点,E::after和E::before伪元素选择器插入内容,体现了纯CSS写评分的技巧,代码少且优美。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载:https://www.cnblogs.com/hesj/p/10536792.html

用到的知识:
E:checked:单选或复选框被选中

E ~ F: 选择后面的兄弟节点们:选择后面的兄弟节点

E::after,E::before: 伪元素选择器 在匹配E的元素后面(前面)插入内容

<!DOCTYPE html>
<html>
    <div class="star-box">
        <input type="radio" name="star" id="star5" hidden/>
        <label for="star5"></label>

        <input type="radio" name="star" id="star4" hidden/>
        <label for="star4"></label>

        <input type="radio" name="star" id="star3" hidden/>
        <label for="star3"></label>

        <input type="radio" name="star" id="star2" hidden/>
        <label for="star2"></label>

        <input type="radio" name="star" id="star1" hidden/>
        <label for="star1"></label>
    </div>
</html>
<style>
.star-box{display:table;position: absolute;left: 50%;top: 50%;}
.star-box label{float:right;color:#999;}
.star-box label::after{content:'★';font-size:28px;padding:5px;display:inline-block;line-height:1;}
.star-box input:checked~label,
.star-box label:hover~label,
.star-box label:hover{color:red;}
</style>

效果截图
结果如上图所示,纯CSS写评分还是技巧的一种体现。这种方式不仅优美而且代码少。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值