How the background-size of the mobile CSS sprites is calculated.

Source: Internet
Author: User


This is the first problem that has been encountered in the recent practice of mobile instances. How to find the picture position you need.

In addition, I see that CSS sprites is much faster than Dataurl, but I am looking at an analysis of the 13, many years past, do not know how the latest.

I do not know whether to write the image element is the IMG tag or use background it?

The following is a look at how to calculate the Background-size data. Thanks for sharing.

When normal PC settings:

1. S1{
2width:22px;Height:38px;background-position:-118px-0px;
3Background-image:URL (images/icon2b.png);
4Display:Inline-block;
5}

But on iOS, because the iphone is double-displayed, so:

@media screen and (-webkit-min-device-pixel-ratio:2), screen and (Max-moz-device-pixel-ratio:2){
. s1{
Width:11px;Height:19px;/*half before the target.*/
Background-position:-59px-0px;/*change before half*/
Background-image:URL (images/icon2b.png);
Display:Inline-block;
Background-size:180px 180px;/*size is half the size of a CSS sprites picture*/
}

}


the background-size is calculated as follows:

High resolution image width (PC)/target image width (phone) = X

Original sprites image width/x = background-size Width value

Here I set the computer picture width for (computer): 22

Here I set the phone target width is: 11

The original sprites image size is: 360*360

x=22/11=2

Background-size Width: 360/x=180px

background-position:-59px 0 (calculation method: Original (-118) divided by x)

Thank: Source:http://www.luchanan.com/archives/322

How the background-size of the mobile CSS sprites is calculated.

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.