利用层的定位、层的顺序以及背景定位来实现的星级评分。
HTML部分:
<h1>CSS: Star Rating Redux</h1> <ul class="star-rating"> <li class="current-rating" style="width:60%;">Currently 3/5 Stars.</li> <li><a href="#" title="1 star out of 5" class="one-star">1</a></li> <li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li> <li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li> <li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li> <li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li> </ul>
<h1>CSS: Star Rating Redux inline</h1> Rate this: <span class="inline-rating"> <ul class="star-rating small-star"> <li class="current-rating" style="width:30%;">Currently 1.5/5 Stars.</li> <li><a href="#" title="1 star out of 5" class="one-star">1</a></li> <li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li> <li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li> <li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li> <li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li> </ul></span> And This: <span class="inline-rating"> <ul class="star-rating small-star"> <li class="current-rating" style="width:80%;">Currently 4/5 Stars.</li> <li><a href="#" title="1 star out of 5" class="one-star">1</a></li> <li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li> <li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li> <li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li> <li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li> </ul> </span> <h1>Let''s make it smaller</h1>
<ul class="star-rating small-star"> <li class="current-rating" style="width:50%">Currently 2.5/5 Stars.</li> <li><a href="#" title="1 star out of 5" class="one-star">1</a></li> <li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li> <li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li> <li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li> <li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li> </ul> 这部分的关键在于current-rating,把它的宽度定为50%,然后设置背景平铺,之后把它的层的顺序设为最低,这样就会形成一个初始的分值。 再就是a标签和hover的灵活应用了:上面的例子中一共有5个a标签,那么每个a标签的宽度就是20%,以此类推给每个a标签都定一个不同的宽度;接着,给每个a标签都定义不同顺 |