Sunday, July 5, 2009

Display n number of stars in HTML/CSS

This weekend I was trying to figure out how to display a specific number of star images given an integer. I could have looped through n images but then my html code will look messy. I decided to do it with CSS. Another requirement will be to place the stars as an inline element with my text. Using span and displaying it as inline-block seems to have solved this issue. I noticed that Amazon uses a more elegant technique by only showing chunk of a larger image of stars.


No comments: