一句话实现星级评价
"★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate); //rate是0~5的整数 //或者: "★".repeat(rate) + "☆".repeat(5-rate);
<div class="star"> <span class="hide"></span> <span>★</span> </div>
<style> *{ padding: 0; margin: 0; overflow: hidden; } .star{ position: relative; } .hide{ position: absolute; left: 7px; top:4px; background: #fff; width: 10px; height: 14px; } </style>
半星效果