Mobile phone-side REM usage

Source: Internet
Author: User

!function (n) {    var  e=n.document,         t=e.documentelement,         i=720,         d=i/100,         o= " Orientationchange "in n?" Orientationchange ":" Resize ",         a=function () {             var n=t.clientwidth| | 320;n>720&& (n=720);             t.style.fontsize=n/d+ "px"         };         e.addeventlistener&& (N.addeventlistener (o,a,!1), E.addeventlistener ("domcontentloaded", a,!1)} (window);

Method 2

Window.onload =function(){    /*720 on behalf of the designer to give the width of the design manuscript, your design draft is how much, write how many, 100 represents the conversion ratio, here write 100 is to calculate later, for example, you measure a width is 100px, can write as 1rem, and 1px=0.01rem and so on*/Getrem (720,100)};window.onresize=function() {Getrem (720,100)};functionGetrem (pwidth,prem) {varhtml = document.getelementsbytagname ("html") [0]; varOwidth = Document.body.clientWidth | |Document.documentElement.clientWidth; Html.style.fontSize= Owidth/pwidth*prem + "px";}

First of all, first of all, a common sense, the browser's default font height is 16px

The basic idea is: the use of REM units, is relative to the size of the (HTML) font, to calculate the width of the corresponding element is generally set to the HTML font-size: 20px or 30px or 50px or 100px and the use of the browser default size (16px) is 16px *62.5%=10px, this is html{font-size:62.5%;}, not html{font-size:10px;} Because the smallest browser (PC) is 12px. So 1rem = 10px; Let's take a quick look: <div id= "wrap" >      <div id= "Div1" > I'm a div tag </div></div>css setting style # wrap{   
font-size:20px;
} #div1 { font-size:1em; Width:16em; Height:2em; Background-color:lawngreen;}

  

Mobile phone-side REM usage

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.