Mobile page REM Layout

Source: Internet
Author: User
Tags copy return window

Mobile Phone page design is generally the size of 640, but the size of the mobile phone screen is really uncertain, so, how to make the adaptation of all mobile phone page?
There are two common solutions, REM layout and percent layout. I have tried both of these options, so now it is more recommended to use REM layout to make mobile phone pages;

REM Layout compatibility:
Mozilla Firefox 3.6+, Apple Safari 5+, Google Chrome, ie9+ and opera11+, Ie6-ie8 or no REM
But now the general mobile phone browser, you can generally directly do not have to pipe IE kernel browser.

REM Calculation Formula
Example: HTML settings font-size:16px 1rem = 16px
So 640px = 640/16 =40rem

Personal recommendation set to 100px convenient calculation

First, define a 100px
html{font-size:100px for the HTML of the page; /* Set the base rem*/

Then, the most core code is this section of JS operation, based on the size of the page to control the value of REM;

New function () {
var _self = this;
_self.width = 640;//Set Default maximum width
_self.fontsize = 100;//default font size
_self.widthproportion = function () {var p = (document.body&& Document.body.clientWidthdocument.getElementsByTagName ("HTML") [0].offsetwidth)/_self.width;return P>1?1:p <0.5?0.5:p;};
_self.changepage = function () {
document.getElementsByTagName ("HTML") [0].setattribute ("Style", "Font-size:" +_self.widthproportion () *_ self.fontsize+ "px!important");
}
_self.changepage ();
Window.addeventlistener ("Resize", function () {_self.changepage ();},false);
};

Demo

<! DOCTYPE html>  


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.