CSS Sprites-website CSS Background Image Positioning

Source: Internet
Author: User

This technique has been widely used in front-end development of current pages. Even Yui sets it as the first criterion "make fewer HTTP requests" in "14 guidelines for improving webpage efficiency ", the importance of this technology is also the recommendation of Yui.
This CSS technique has been widely promoted and applied.

Let's take a look at the simplest Demo:
This is the background image:

This is a simple demo of CSS Sprites:

 

XML/html code: <br/> <Div style = "" float: Left; "mce_style =" "float: Left;" width: 120px; padding-left: 20px; background: url(ico.png) Left top no-repeat "> Red Cross </div> <br/> <Div style =" "float: Left;" mce_style = "" float: left; "width: 120px; padding-left: 20px; Background: url(ico.png) left-32px no-repeat "> green check box </div> <br/> <Div style =" "float: Left;" mce_style = "" float: left; "width: 120px; padding-left: 20px; Background-image: url(ico.png); background-position: Left top; Background-repeat: no-repeat "> Red Cross </div> <br/> <Div style =" "float: Left;" mce_style = "" float: Left; "width: 120px; padding-left: 20px; Background-image: url(ico.png); background-position: 0-32px; Background-repeat: No-repeat "> green check box </div> 

CSS Sprites principles
CSS Sprites is actually to integrate some background images in the webpage into an image file, and then use CSS's "background-image", "background-repeat ", the combination of "background-position" to locate the background. The background-position can be used to precisely locate the background image position.

 
Advantages of CSS Sprites
1. the use of CSS Sprites can effectively reduce HTTP requests for webpages and greatly improve the page performance. This is also the biggest advantage of CSS Sprites and is also the main reason for its wide spread and application;
2. I personally think that CSS Sprites can reduce the size of the image. I have compared the size of the three images that are merged into one image multiple times to be smaller than the total size of the three images.

 

Disadvantages of CSS Sprites
It is true that CSS Sprites is so powerful, but there are also some shortcomings that cannot be ignored.
1. when merging images, You need to combine multiple images into one image in an orderly and reasonable manner, and leave enough space to avoid unnecessary background in the Section, what is painful is the Adaptive Page under a wide screen or high-resolution screen. If your picture is not wide enough, it is easy to break the background;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.