CSS Sprite image creation, CSS Sprite Image

Source: Internet
Author: User

CSS Sprite image creation, CSS Sprite Image

CSS Sprite:

To improve web page performance and reduce loading times, place small icons that do not change frequently with the website content on a large image and embed the image into the page as a background-image, set the coordinates based on background-position when you need to associate the map.

 

For example, you can copy and view the results:

HTML code:

<! DOCTYPE html> 

 

CSS code:

/* General settings */. container ,. menu {margin: 0; padding: 0; line-height: 0;} a: link, a: visited {text-decoration: none; color: inherit;}: hover {color: orangered;}/* format setting */. menu {width: 120px; list-style-type: none; border: 1px solid # ccc ;}. menu li {display: block; height: 31px; line-height: 31px;} li h3 {font-size: 14px; font-weight: 400; border-bottom: 1px solid # eee;} li I {background: url ("img/sprite.png"); display: inline-block; float: left; width: 24px; height: 24px; margin: 0 15px 5px ;}. cat-1 I {background-position: 0 0 ;}. cat-2 I {background-position: 0-26px ;}. cat-3 I {background-position: 0-52px ;}. cat-4 I {background-position: 0-78px ;}. cat-5 I {background-position: 0-pixel PX ;}. cat-6 I {background-position: 0-130px ;}. cat-7 I {background-position: 0-156px ;}. cat-8 I {background-position: 0-182px ;}. cat-9 I {background-position: 0-208px ;}. cat-10 I {background-position: 0-236px ;}

This is a graph created using a Sprite online production tool. Link: http://lazytools.sinaapp.com /. Other tools are not clear, but the tool will generate CSS information for the position corresponding to the icon at the end, which can be used directly, very convenient.

The following is the final result:

Conclusion: for beginners, learning a new knowledge point requires more exercises and writing code by themselves. It does not work when watching videos, in practice, various problems may occur, and multiple exercises are also the best way to keep improving.

I don't know if you know how to make and use sprite images. Now I will.

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.