Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've observed that often the websites use only one background image which contains multiple images on it. For example, instead of using separately icons, all of the icons are put on one image and then the different parts of image are used in different section. Is there any advantage of this? Also, How can this be used? For example, the following Yahoo's images, if i want to display the second icon in a div, how would I do it? and what is advantage of it?
Posted
Comments
Prasad Khandekar 24-Mar-13 6:38am    
Hello Rahul,

This is typically done to reduce the roundtrips that a browser has to make in order to display the web page. When browser loads the HTML it also has to fetch the various images, css, script files referenced within it. By combining multiple images browser has to download only a single image. By the way this is possible because CSS specification also supports it via position attributes of background rule.

Regards,

For me, I got lazy or move advanced, and started using image strips, I'm setting the CSS anyways, so why not just move the image over to the left for icon 2. So now I have less artwork to track, it's faster, download the image once.

in the css, you specify the background-position,

background-image: url('/image.png');
background-position: 0px 16px;

http://www.w3schools.com/cssref/pr_background-position.asp[^]
 
Share this answer
 
v2
Hi.. Really you asked best question.. Here is the reason why we should combine multiple images into one..

1. Each images used in webpage is considered as a one http request while loading.
2. Webpage load time depends on number of requests in a page.
3. As the number of requests is less obviously page load time is less.
4. Also if you use multiple images they consume more space, so better to combine them into one.

See below links to know about positioning background images..
http://www.w3schools.com/cssref/pr_background-position.asp[^]
http://www.w3schools.com/cssref/playit.asp?filename=playcss_background-position[^]

Below link will clearly show solution to your question..
http://css-tricks.com/css-sprites/[^]

Hope this helps you lot...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900