CSS: Star Rater Example 1
Currently 3.5/5 Stars.
1
2
3
4
5
Resources:
Both the XHTML and the CSS are provided below.
XHTML:
<ul class='star-rating'> <li class='current-rating'> style='width:105px;' Currently 3.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>
CSS:
/* styles for the star rater */ .star-rating{ list-style:none; margin: 0px; padding:0px; width: 150px; height: 30px; position: relative; background: url(star_rating.gif) top left repeat-x; } .star-rating li{ padding:0px; margin:0px; height:30px; width: 30px; /*\*/ float: left; /* */ } .star-rating li a{ display:block; width:30px; height: 30px; line-height:30px; text-decoration: none; text-indent: -9000px; z-index: 20; position: absolute; padding: 0px; overflow:hidden; } .star-rating li a:hover{ background: url(star_rating.gif) left center; z-index: 2; left: 0px; border:none; } .star-rating a.one-star{ left: 0px; } .star-rating a.one-star:hover{ width:30px; } .star-rating a.two-stars{ left:30px; } .star-rating a.two-stars:hover{ width: 60px; } .star-rating a.three-stars{ left: 60px; } .star-rating a.three-stars:hover{ width: 90px; } .star-rating a.four-stars{ left: 90px; } .star-rating a.four-stars:hover{ width: 120px; } .star-rating a.five-stars{ left: 120px; } .star-rating a.five-stars:hover{ width: 150px; } .star-rating li.current-rating{ background: url(star_rating.gif) left bottom; position: absolute; height: 30px; display: block; text-indent: -9000px; z-index: 1; } /* remove halo effect in firefox */ a:active{ outline: none; }