views:

13

answers:

1

Is it possible to put multiple repeating gradients on a single sprite master image? I've got about 5 1px X 400 px gradients that could be combined to reduce the page requests. It's pretty much my last place to go for reducing object requests. I haven't seen any techniques for this while searching. My own experimentation hasn't had good results.

+1  A: 

Assuming that all the areas you're applying the background gradients to are less than 400px high, you can tile the five sprites vertically to give you a single 1x4000px image.

You could apply the appropriate part of the sprite by specifying a vertical offset, and setting background-repeat:repeat-x.

The vertical offset would be 400 * (index of the sprite you want): 0px for the first, 400px for the 2nd, 800px for the 3rd, etc.

meagar
Here is my without any critical thinking immediate response. Will this work with sprites of odd widths as well?
Jason Tabler
All the sprites have to be the same width, otherwise you'll have strips of blank space between them when they're repeated. This shouldn't be a problem if the sprites are meant to tile horizontally anyways...
meagar
I was thinking about using radial gradients, but I guess they will have to be linear. So, really, you can get away with three sprites overall - all your static background images, a sprite for vertical linear gradients, and a sprite for horizontal linear gradients. Way cool. Thanks.
Jason Tabler