I was wondering if there is any way to use just one image for repeating and non-repeating images using css sprites. So in this case I would like to combine all the images on a page no matter what width and height and if they will be used as repeating or non-repeating images. I know the standard is to create 1 image using all the non-repeating images and another image using all the repeating images. But i just wanted to know if i could just use 1 image for everything.
Thanks.
The short answer is "no".
The explanation is that repeating images are displayed in their entirety in whatever direction they repeat. So, a background that is set to repeat-x
will show all image content in the horizontal direction. This is why you can't repeat in both directions simultaneously using sprites.
I know the standard is to create 1 image using all the non-repeating images and another image using all the repeating images.
I think you are mistaken. It's impossible to selectively tile a segment of an image. You can only tile an image in its entirety. Thus, all repeating images must live in their own image files.
@Ryan Kinal is right when saying in his answer that a sprite image can't be used for repeating background images (in both directions).
There is still a way to do it cross-browser with only one or two files (not images), but it isn't that simple and should prove complicated to modify (though sprites are also complicated to modify, but at least it's visual!).
As stated in the PHPIED article, the inline images are repeated twice but with the help of 3 conditional comments you can aim IE7 and below with the MHTML file, IE8 and above with the data: base 64 file and !IE with the same data file.
You end up with 5 different files on your server and 4 downloaded by any given browser:
no-repeat
-ing spritesrepeat-x
-ing spritesrepeat-y
-ing spritesLarge repeating images shouldn't be encoded as filesize could increase a lot, your design may vary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With