Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I still need to pad images in a CSS Sprite?

Tags:

In CSS Sprites you will often find padding between each image. I believe the idea is so that if the page is resized then one image won't bleed into another.

I think this depends on the different types of browser zoom (best explained by Jeff).

However, I haven't been able to see this behaviour in my tests. Is this only a problem with older browsers? (I havent been able to test with IE6 at the current time so I'm counting that as 'old').

Should I still worry about leaving space? Its kind of a pain.

For instance :

A CSS Sprite I found for AOL has padding between each image : VIEW

but The Daily Show decided not to bother : VIEW

like image 590
Simon_Weaver Avatar asked Mar 14 '09 23:03

Simon_Weaver


People also ask

Why is it advisable to use a sprite sheet containing all the images?

Sprite sheets increase the performance of your game and reduce the loading and startup time. The game uses a few big image instead of hundreds of small images. This also allows sprite batching — the rendering system draws the sprites with a few draw calls instead of sending isolated commands for each sprite.

Should I use image sprites?

A web page with many images can take a long time to load and generates multiple server requests. Using image sprites will reduce the number of server requests and save bandwidth.

How do CSS Sprites work?

CSS Sprites are a collection of images that are combined into a single file that an HTML document can access. These images are then called into use within the HTML code to be displayed on the website.


1 Answers

It shouldn't need to be padded, but when zoomed, especially in IE8 (betas more than the RC), there is image bleeding if there is no padding.

Best example is to go to Google.com -> Search, and zoom... you'll start to see "underlines" at the bottom right of the image as the zooming rounds up/down.

In theory, a 1px padding on all sides of a sprite should be fine.

Here's the sprite from Google (images)...

alt text

But when zoomed, the +,-,x icons bleed into the main Google logo.

alt text

like image 86
scunliffe Avatar answered Oct 12 '22 22:10

scunliffe