The basic concept behind this tip is to make a div of particular height and use an empty star image ( assume grey bordered star that will act as blank star ) which will be repeated in x-axis and look something like below
Then we need to create another div inside it with same height, and the background will be set dynamically later as per the required rating. This div will be having the background as the full start (assume golden color star) which have been set to repeat only in x-axis.
If the rating is 2 out of 5, the inner div will cover upto 40% width of the outer div, so basically we can see the background of the inner div and rest 60% will be the background of the outer div. It will look somethig like below:
<div class="fullRatingDiv" style="width: 40px"></div>
Note: The inline style for width can be specified by templating or by scripting. It need to be set in px.
CSS – ( Assuming the dimension of the star image to be 20 X 20 )
width: 100px; /* 20 * 5 px */
background: url(emptystar.png) repeat-x;
background: url(fullstar.png) repeat-x;
So the final design will look like below,
That’s it, now the same concept can be applied to make cool progress bars.