1. 程式人生 > >CSS繪製星星評分實現分析

CSS繪製星星評分實現分析

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

實現原理:設定包含星星的I元素高度後,然後設定其邊框上下寬度為0,然後左右寬度為I元素高度的一半,需要實現半個星星時就使用border-left-color:屬性。其他則設定一般的邊框即可。IE6下不相容