Utilize a jQuery Star Rating Plugin.
Refer to the second half for an alternative method using only CSS.
Take a look at this screenshot from the jQuery Star Rating Plugin. For more plugin examples, visit the Database Integration Tab, or search for additional jQuery Star Plugins HERE.
Screenshot:
Reference:
Check out this Demo for the jQuery Star Rating Plugin
Screenshot of jsFiddle jQuery Star Rating Demo:
The minimal HTML markup required for the jQuery Star Rating Plugin is as follows (completely customizable):
<span class="bookFiveStar">
<input name="book002" type="radio" class="star" disabled="disabled"/>
<input name="book002" type="radio" class="star" disabled="disabled"/>
<input name="book002" type="radio" class="star" disabled="disabled" checked="checked"/>
<input name="book002" type="radio" class="star" disabled="disabled"/>
<input name="book002" type="radio" class="star" disabled="disabled"/>
</span>
Here are two distinct solutions for this answer.
Opt for a Pure CSS Rating System without relying on a jQuery plugin or JavaScript.
Refer back to the first part above if you prefer using the jQuery Star Rating Plugin.
The reference image utilized was sourced from hot-linkable imageshack.us and is displayed below.
The dimensions are set as width:98px;
and height:143px;
with the image format being jpg
.
Reference:
View the Demo for the Pure CSS Star Rating
Screenshot of jsFiddle Pure CSS Demo:
Minimal HTML:
<div class="starsCSS">
<img class="stars3" title="3 Stars" src="http://img366.imageshack.us/img366/6441/stars.jpg" alt="Star Rating Image" />
</div>
Complete CSS:
/* This class name configures and positions the 6 star image block. */
.starsCSS{
/* The width of the star block uses the entire star.jpg width */
width: 98px;
/* The height of the star block is LIMITED to 23px, i.e. 1 star row. */
height: 23px;
/* This overflow:hidden will ensure only 1 row is ever seen, when aligned properly.
/* That said, later below different classname uses margin-top negitive offset to align. */
overflow: hidden;
/* The placement of the star block is relative to other elements. Adjust px here. */
position: relative;
top: 10px;
left: 155px;
/* Simple light blue border is provided for the image./
/* Your cusom star image may be a .png with transparency so remove this setting. */
border: 2px solid DodgerBlue;
}
/* This CSS Selector consists of classname .starsCSS that has 'img tag'. */
/* This rule will set original image width and original image height for stars.jpg file. */
.starsCSS img{
width: 98px;
height: 143px;
}
/* These 6 classes will position the image so that only the relevant "star row" is seen for .starsCSS */
/* Technically, this first class .stars1 is not needed since nothing changes. */
/* Note stars.jpg is used full width (98px), therefore it's 1 column. */
/* Use margin-left with negative value if your custom image.jpg has 2 or more columns */
/* IF stars.jpg was double in width then "margin-left: -98px;" will hide first column */
.stars1{
margin-top: 0px;
}
/* Reference Image: 143px height divide by 6 star rows = 23.833333px per row. */
/* Hence, star.jpg image is not perfect and it's rounded to 24px per row instead */
/* Since 1 star row is 24px high, classname .stars2 will offset that to get to next row. */
/* That said, the value needs to be negitive since entire image is shifted up (offset). */
/* The class .starsCSS will now show the second star row! */
.stars2{
margin-top: -24px; /* Shift up star row 1 */
}
.stars3{
margin-top: -48px; /* Shift up star rows 1 and 2 */
}
.stars4{
margin-top: -72px; /* Shift 3 rows of stars out of view (24 x 3 = 72 ) */
}
.stars5{
margin-top: -96px; /* Shift 4 rows of stars out of view */
}
.stars6{
margin-top: -120px; /* Shift 5 rows of stars out of view */
}