Consider the following example:
HTML:
<div id="julia" class="photo"></div>
<div id="rachel" class="photo"></div>
<div id="martin" class="photo"></div>
CSS:
.photo {
width: 60px;
height: 60px;
display: inline-block;
}
.photo:hover {
background-position: -60px 0;
}
#julia {
background-image: url('http://www.mypicx.com/uploadimg/1312875436_05012011_2.png');
}
#rachel {
background-image: url('http://www.mypicx.com/uploadimg/1932001963_05012011_1.png');
}
#martin {
background-image: url('http://www.mypicx.com/uploadimg/2082029375_05012011_3.png');
}
This example demonstrates what I want to achieve.
The HTML is generated by Rails 3 application. It should display all the users in a specific group (this info is stored in the database). In other words, the list of users to display may vary.
The problem is that I don't want to have this code:
#username {
background-image: url('/path/to/username/sprite');
}
for each existing username. Moreover, if a new user is added, I don't want to change the CSS.
The question is: Is that possible to achieve the same effect using external CSS ?