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>