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

怎甘沉沦 提交于 2019-12-18 10:53:10

问题


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


回答1:


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)...

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




回答2:


Basically the answer is yes. Two years to the day after I asked this question will see the release of IE9. IE9 has this problem just as much - if not more than any other browser...

It's pretty infuriating because it's such a simple thing to fix.

With iPads increasing in marketshare - its's pretty essential to at least have a half decent experience with zooming un-uniform amounts.

I am going to have to put a single pixel border around every image to match the background color of the adjacent element (potentially different on each side). Fortunately I auto-generate all my csssprites based on an .xml file - so I can do this programatically without too much hastle. It's still a huge pain though...




回答3:


Simon - My experience is that this is certainly still a problem.

In response to your second question, why not use transparent padding? (Perhaps you are still supporting ie6 and this is non-trivial, in which case, I'm really sorry).




回答4:


Speaking of the older browsers (those using text zoom), you don't always need padding.

The main difference between your two examples is that the Daily Show sprite already includes the menu item's text in the image itself.

When using text zoom, the AOL menu items could stretch out vertically due to the larger font size, and the menu text might even wrap to two lines. To accommodate for such eventualities, those icons need a little padding to ensure they don't bleed. Typically, you'd just try to make sure it doesn't bleed on any of IE6's five text sizes.

Since The Daily Show's menu doesn't contain any (visible) HTML text its size won't be affected by text zoom (though you might need a line-height: 0; or so to be sure), so it doesn't need any padding.

As scunliffe already showed, browsers using page zoom may need sprites to have a little padding due to rounding errors.



来源:https://stackoverflow.com/questions/646901/do-i-still-need-to-pad-images-in-a-css-sprite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!