Web-Mobile adaptation

Source: Internet
Author: User

    1. Set viewport to device width (not necessarily here, but this is the way to go)

    2. Divide the viewport into 10rem, and calculate 1rem in the current browser pixel value, give it to the HTML tag font-size (divided into 10rem just for the convenience of calculation)

    3. When you write CSS code, you encounter the place to adapt, such as width,margin,padding, and so on, do not use PX, changed to REM

JS and HTML code are as follows:

<! DOCTYPE html><Htmllang="ZH-CN" ><Head><Metacharset="Utf-8" ><MetaName="Viewport"Content="Width=device-width, Height=device-height" ><Title> beetle's path to the pit</Title><ScriptType="Text/javascript" > var Cssel =Document.createelement (' Style ');Document.documentElement.firstElementChild.appendChild (Cssel);function setpxperrem (var DPR = 1; //viewport is divided into 10 parts rem,html label Font-size set to 1rem size; var pxperrem = document.documentelement.clientwidth * DPR/ Span class= "Hljs-number" >10; cssel.innerhtml =  "html{font-size: ' + pxperrem +  ' px!important;} ';} Setpxperrem (); </script></ head><body> </body></ HTML>             

The CSS code makes a change like this:

Web-Mobile adaptation

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.