A few notes on the mobile side of the page

Source: Internet
Author: User

I believe you will not be too unfamiliar with mobile page development, but what is the difference between it and the PC page?

1. Responsive layout

The so-called responsive layout, the core content is media, it is similar to and if the wording

@media (condition) {

/* CSS statement */

}

Give me a chestnut:

A div with a screen resolution of 320px and 980px plus a background:red CSS style

@media (max-width:980px and min-width:320px) {    div{        background: red;    } }

PS: Similar to the wording of the @supports, CSS3 of the condition of only 2 judgment:

One is the "@media" rule, which is used primarily to "differentiate style sheets based on media properties."
The second is the "@supports" rule, which implements a progressive enhancement design under a browser that does not support CSS3.

/**/{section  {     display: flex;     Background: red;  } }    /** *{section  {     float:  left;     background: green;  } }    

2.media_viewport and REM

<name= "Viewport"  content= "width=device-width,user-scalable=0, initial-scale=1.0 "/>

I believe you are not unfamiliar with the above code, this is the mobile page must add meta, this on the following HTML fontsize calculation has an impact, the most commonly used Conten attribute T on the above to write these 3, remember these three basic on the line.

If you do not add this meta viewport clientwidth will be parsed into the browser default values, such as 980px, 1024px, etc., will eventually affect the HTML font-size calculation ~ ~

When it comes to REM, you have to mention that Em,em is defined relative to the font size, such as a Div's font-size:12px then its 2em is equivalent to 24px.

and REM is relative to the font-size of the HTML tag, so we want to write some pages that change with the size of the screen (compatible with different resolution pages), we can consider the REM unit, and we just need to calculate each time we window.onload.

function () {    //designwidth/own favorite Font size = 846px/100px = 8.46    //  We use the benchmark FontSize is 100 is easy to calculate, the design manuscript px conversion to REM only need to divide by the    document.documentElement.style.fontSize = document.documentelement.clientwidth/8.46 + ' px ';}

So generally we use the actual device width/(Design draft width/100) to calculate the size of the HTML fontsize, then all the unit size are installed design draft of 1/100 times times to write OK, of course, we put 100 directly into 1 is OK, This will be more convenient, mainly to see personal habits.

PS: Some developers also like to use percentages to define HTML fontSize such as 62.5%, most of the browser default font size is 16px, so 62.5%*16 = 10, into 10px is convenient to write style ~

3.touch Events

1. Single Point

Mainly including Touchstart Touchmove touchend, of course, this is the Dom3 event, to be compatible with the best written event binding (AddEventListener) in the form of good ~ ~

A few notes on the mobile side of the page

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.