CSS绘制星星评分实现分析

效果图:

 

    <div class="rating rating-3-half">
      <i class="star-1"></i>
      <i class="star-2"></i>
      <i class="star-3"></i>
      <i class="star-4"></i>
      <i class="star-5"></i>
    </div>

 

.rating {
  margin: 10px 0;
}
.rating-3-half .star-4 {
&nbsp; border-left-color: #f0991e;
}
.rating i {
&nbsp; display: inline-block;
&nbsp; width: 0;
&nbsp; height: 1.5em;
&nbsp; border-width: 0 0.75em;
&nbsp; border-style: solid;
&nbsp; border-color: #eee;
&nbsp; border-radius: .22em;
&nbsp; color: white;
&nbsp; background: #eee;
&nbsp; font-style: normal;
&nbsp; line-height: 1.6em;
&nbsp; text-indent: -0.5em;
&nbsp; text-shadow: 1px 0 1px #b3b3b3;
}

实现原理:设置包含星星的I元素高度后,然后设置其边框上下宽度为0,然后左右宽度为I元素高度的一半,需要实现半个星星时就使用border-left-color:属性。其他则设置一般的边框即可。IE6下不兼容

posted @ 2014-10-27 14:46  若叶知秋  阅读(257)  评论(0编辑  收藏  举报