CSS sprites, how to plan?

Source: Internet
Author: User

First look at a picture:

    1. How many CSS backgrounds does a page typically load?
    2. What are the typical types of sprite?
    3. How large is the size of the sprite chart? How to arrange?
    4. How does sprite map distribute in the site?

Have you ever bothered with the above issues? With the above points, we will discuss the site of the snow blue map How to plan more reasonable.

First of all, let's recall what types of footage are used when cutting the page?

I try to think ... Hard to think Ah ... There are probably: buttons, icons, other fixed-size background, vertical tile background, horizontal background map, background map, left and right adaptive background, up and down adaptive background, brightly colored and large size background.

It seems a bit messy, let's divide the class.

the scope used by Sprite can be divided into: Cross Project General, global, column level, page level

According to the snow-blue diagram to achieve the way can be divided into: fixed size sprite, horizontal shop Sprite, vertical snow blue map (less use), or vertically tiled background map (less use)

Then, we will recall the material map of the class:

by Scope: These materials may appear in different scopes at different sites

By way of implementation:

    • Fixed size sprite: Buttons, icons, other fixed-size background, brightly colored, larger-than-size background images
    • Cross-paved sprite: Horizontal spread background map, left-right adaptive background map (without the use of nine Sudoku Implementation)
    • Vertical Snow Blue Map: Vertical background map, up and down adaptive background map (without the use of nine Sudoku Implementation)
    • Tile background map: This kind of diagram can not synthesize sprite map, generally used for Web page background pattern, most sites are less than appear

Finally, how many Zhang Xiebi should we do from the site's achievable nature? Take a look at this table below:

From the table, you can analyze the number of requests for a page's background image:

Is it shocking to see the most situation? Oh, in fact, very few will happen to use the situation, according to the actual situation of the page combination, the number of requests will not be many, compared with the first illustration of the background map request number, the planning is much clearer, the number of requests also reduced a lot.

How can these graphs be cut, distributed, and named, and there is nothing particular about them? Here are my personal opinions and suggestions:

    1. Horizontal map width using 20px, the use of 1px width of the spread will have rendering performance problems, vertical paving the same. I will not elaborate on the internet search, there are related examples.
    2. The fixed size of the sprite can generally be set to width is half the width of the page, height with the picture content growth. Because you may not know the size of the picture before you cut it, my opinion is that by the end of the Chettu you may not need to use a repeat-x.png map to put an adaptive background map, in most cases, we will use 2 tags to use the sliding door to achieve an adaptive background, and page width Half of the time to achieve the maximum width of the left and right adaptive background, then you can put the adaptive background into this sprite picture
    3. When you flatten a picture, the fixed size diagram is 1 pixels apart from the diagram, so that when you enlarge the browser, you can see the adjacent picture when the size is 1 pixels.
    4. Column-level sprite name according to the column level directory name, page-level sprite name by the name of the page, component class and skin-like sprite diagram of the same, other can be named by the name of the table, so that easy to distinguish and later management
    5. Cross-project common components or a component of the picture content more, frequently modified, you can independently out a component diagram, named after the component name, easy to manage
    6. If the site's global icon is more, you can consider the icon to do a separate sprite picture
    7. Suggest the icon to use a new tag to implement, rather than directly with the content of the tag to set the icon background, so you need to give the sprite icon and the icon to leave some space between, and encountered different row height, in order to make the icon background vertical Center, but also need to reset background-position, This implementation is bad for incorporating global styles


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.