Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

220 lines (131 sloc) 8.864 kb
<!doctype html>
<!--[if lt IE 9]> <html class="no-js oldie" lang="en"> <![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Creating Rating Sprites | Divya Manian</title>
<meta name="author" content="Divya Manian">
<meta name="description" content="I came across this Youtube HTML 5 demo via Laura Carlson and was amazed at their simple sprite solution for static ratings display. Here is how to &hellip;">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="">
<link href="/stylesheets/screen.css" rel="stylesheet">
<link href="" rel="alternate" title="Subscribe" type="application/atom+xml">
<link href="" rel="alternate" title="Subscribe to Web Development updates" type="application/atom+xml">
<body >
<div class="container">
<div class="content">
<header role="banner"> <h1><a href="/">Divya Manian</a></h1>
<h2><a class="twitter" href="">twitter</a> <a class="rss" href="">RSS Feed</a> <a class="youtube" href="">Youtube Channel</a> <a class="github" href="">Github</a></h2>
<nav class="sitenav"><a href="/">Home</a>
<a href="/archives">Archives</a>
<a href="/about.html">About</a>
<nav class="article">
<a class="previous" href="/book-reviews-for-november-2009-part-1.html" title="Book Reviews for November 2009 — Part 1">❬</a>
<a class="next" href="/book-reviews-for-november-2009-part-2.html" title="Book Reviews for November 2009 — Part 2">❭</a>
<time datetime="2009-11-09T00:00:00-08:00" pubdate><span class='month'>Nov</span> <span class='day'>09</span> <span class='year'>2009</span></time>
<h1 class="entry-title"><a href="/creating-rating-sprites.html">Creating Rating Sprites</a></h1>
<div class="entry-content"><p>I came across this <a href="">Youtube HTML 5 demo</a> via <a href="">Laura Carlson</a> and was amazed at their simple sprite solution for static ratings display. Here is how to create one.</p>
<p>This solution is only for displaying a static rating and not an <a href="">animated one</a>.</p>
<p>I am using the word &ldquo;star&rdquo; a bit loosely in this post. The &ldquo;star&rdquo; in the sprite below is a circle for the sake of simplicity.
<p>Create a sprite as shown below. I have created each circle within an imaginary 20px box so that it is easier to style via CSS. You can use my reference <a href="/demo/ratingsprite/stars.psd">Photoshop file</a> where I have used guides to position each circle at intervals of 20px.</p>
<p><img src="" alt="stars sprite"></p>
<p>Put this HTML where you want your ratings to appear:</p>
<pre>&lt;span class=&quot;rating r0&quot;&gt;0/5&lt;/span&gt;</pre>
<p>The class <code>rating</code> will be used to apply all the common style properties. Classes <code>r0</code> to <code>r5</code> will be used to position the sprite as a background image appropriately.</p>
<p>In your CSS file, add the following:</p>
span.rating {
background:url(&quot;star.png&quot;) top left;
width:100px; /* width of the set of 5 stars */
<h3>Creating the rating</h3>
<p>Now we style each of the <code>r0</code> to <code>r5</code> classes. </p>
<pre>span.r0 {
background:-50px 0;
span.r1 {
background-position:-60px 0; /* assuming each star is 20px wide */
<p>and so on&hellip;</p>
If you use <a href="">SASS</a> you can add this to your SASS file:
// 100 is the width of the set of 5 stars and 20 is the width of each
// star (including the space to the right, see the Photoshop file
@for !i from 0 through 5
background-position = &quot;#{-(100 - (20*!i))}px 0&quot;
<p>Here is the <a href="">demo of the star ratings sprite</a>.</p>
<li>Single image, lesser page requests, faster page load.</li>
<li>Small file size</li>
<li>Easier maintainance: You only need to edit one image file in case you want to change the graphic.</li>
<p class="meta">This post was posted by
<a href="/about.html">Divya Manian</a>
<time datetime="2009-11-09T00:00:00-08:00" pubdate><span class='month'>Nov</span> <span class='day'>09</span> <span class='year'>2009</span></time> in
<span class="categories">
<a class='category' href='/categories/web-development/'>Web Development</a>
. If you would like to update this post, <a href="">please send a pull request</a>.
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
<aside id="articles">
<p><img class="avatar" src="/assets/divya.png" height=50> <a href="">Divya Manian</a> is a Web Developer in Seattle. <a href="/about.html">More about me ❭</a></p>
<h2>Posts on Web Development</h2>
<ul><li><a href="/html5please.html">html5please</a></li><li><a href="/mustache.html">mustache, hogan, handlebars</a></li><li><a href="/redesign-notes.html">Redesign Notes</a></li><li><a href="/summary-of-various-exciting-css-drafts-and-proposals.html">Summary of various exciting CSS drafts and proposals</a></li><li><a href="/this-revolution-needs-new-revolutionaries.html">This revolution needs new revolutionaries</a></li><li><a href="/some-css-transition-hacks.html">Some CSS Transition hacks</a></li><li><a href="/safe-css-defaults.html">Safe CSS Defaults</a></li><li><a href="/unplugged-2011.html">Unplugged 2011</a></li><li><a href="/bokeh-with-css3-gradients.html">Bokeh with CSS3 Gradients</a></li><li><a href="/making-pure-css3-demos-better.html">Making "Pure CSS3" demos better</a></li><li><a href="/web-opener-at-opera.html">Web Opener at Opera</a></li><li><a href="/current-color-in-css.html">Current Color in CSS</a></li><li><a href="/css-vocabulary.html">CSS Vocabulary</a></li><li><a href="/active-web-development.html">Active Web Development</a></li><li><a href="/sexy-css3-buttons.html">Sexy CSS3 Buttons</a></li><li><a href="/accessible-css-barcharts.html">Accessible CSS Barcharts</a></li><li><a href="/svg-is-coming.html">SVG is coming!</a></li><li><a href="/wee-marquee.html">Wee! Marquee</a></li><li><a href="/vignettes-with-css3-box-shadows.html">Vignettes with CSS3 Box Shadows</a></li><li><a href="/drop-shadows-with-css3.html">Drop Shadows with CSS3</a></li><li><a class="btn" href="/categories/web-development/">More</a></li></ul>
<footer role="contentinfo"><p>
Copy to your heart’s content 2012 - Divya Manian -
<span class="credit">Powered by <a href="">Octopress</a></span>
<script type="text/javascript">
var disqus_shortname = 'nimbublog';
var disqus_developer = 1;
var disqus_url = '';
var disqus_identifier = '';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<script src="/javascripts/octopress.js"></script>
var _gaq=[['_setAccount','UA-97188-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
Jump to Line
Something went wrong with that request. Please try again.