Front-end questions-what are CSS sprites and pros and cons?

Source: Internet
Author: User

CSS Sprite is a Web page image application processing method. It allows all the scattered images involved in a page to be included in a larger image, so that when the page is accessed, it can only be requested once, without having to send a request to the server again and again.

Its principle is to meet some of the background pictures into a picture file, and then use the CSS "Background-image", "Background-repeat", "background-position" the combination of background positioning, Implement multiple positions of the background, a picture to be done.

Advantages

1 reduce HTTP requests for Web pages to improve page performance

2 Reducing Picture bytes

3 to solve the problem of naming the headache, before a lot of a name, and now a name to take care of

4 easier and easier to maintain when changing the entire Web page style

Disadvantages

1 pictures when merging, to put more than a reasonable orderly combination into one, but also to leave enough space to prevent unnecessary background in the plate, if the widescreen, high-resolution screen of the adaptive page, if the picture is not wide enough, it is easy to appear background break

2 The time cost of flattening pictures is increased, CSS sprites need to measure the exact position of each background unit by Photoshop or other tools when developing.

3 Coding and maintenance time cost will increase, CSS sprites in maintenance, if the page background has a little change, generally will change this merged picture, if in the original place, and can only (best) add pictures, so that the image of the byte increases, but also to change the CSS. A large sprite can cause endless testing and picture state re-placement relative to a simple button that makes it easy to calculate state positions.

4 Not all pictures are backgrounds, background images should be left to buttons and used to decorate elements, and images used to convey important information should be inline in XHTML.

In short, CSS sprite is very useful, but also do not blindly abuse and beyond the limits of a degree, need to understand too much.

Front-end questions-what are CSS sprites and pros and cons?

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.