CSS Sprite Chart

Source: Internet
Author: User

Introduction Edit

Sprite charts are used on many websites that use a lot of small icons. Instead of referencing each small icon to a page in the form of a. png file, using Sprite maps only requires referencing one picture, which is more memory-and bandwidth-friendly.

Implement Edit

Suppose we pass a. Toolbtn class that provides a background image for each element of the class that is applied:

<style> .toolbtn {background:url (myfile.png) display:inline-blockheight:20px width:20px } </style< Span class= "token punctuation" >>

background position, you can define the value of the x, Y axis directly by the URL () in background. Or you can add it by using the Background-position property. For example:

<style> #btn1 {background-position:-20px 0px} < Span class= "token ID" > #btn2 {background-position< Span class= "token punctuation" >:-40px 0px} </style>

ID=BTN1 element background left shift 20PX,ID=BTN2 element background left 40px (assuming that all two elements are added TOOLBTN class, apply the above style definition of the picture effect)

Similarly, you can add the hover state using the following method:

#btn:hover {background-position: [pixels shifted right]px [pixels shifted down]px;}

Deep reading

The Complete demo:http://css-tricks.com/snippets/css/perfect-css-sprite-sliding-doors-button/

CSS Sprite Chart

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.