I'm sure this has been asked, but apparently I can't phrase it quite right for a search.
I'm stuck using a sprite for something, and I'd like to automatically calculate the background position based on the position on the element in the HTML.
Here's some code that hopefully makes more sense (this doesn't actually work, it's just to demonstrate what I want to do):
HTML:
<ul>
<li><!--first item--></li>
<li><!--second item--></li>
<li><!--third item--></li>
</ul>
CSS:
ul li {
background-position-x: (number of previous LIs * 45px) + 45px;
}
What makes me think this may be possible is a bit of code from this article:
:nth-child(N)
- Selects elements based on a simple provided algebraic expression (e.g.2n
or4n-1
). Has the ability to do things like select even/odd elements, "every third", "the first five", and things like that.