rem布局计算(移动端,pc端有兼容性)

 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <script>
 5         function rootREM() {
 6             var W = document.documentElement.clientWidth;
 7             W = (W <= 640) ? W : 640;
 8             document.documentElement.style.fontSize = W / 10 + 'px';
 9             document.body.style.fontSize = W / 20 + 'px';
10         }
11         window.onresize = function () {
12             rootREM()
13         };
14     </script>
15     <meta charset="UTF-8">
16     <title></title>
17     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
18 </head>
19 <body onload="rootREM()">
20 
21 <div style="max- 640px;">
22     <br/>你好,世界!
23     <br/>你好,世界!
24     <br/>你好,世界!
25     <br/>你好,世界!
26     <br/>你好,世界!
27     <br/>你好,世界!
28     <br/>你好,世界!
29     <br/>你好,世界!
30     <br/>你好,世界!
31     <br/>你好,世界!
32     <br/>你好,世界!
33     <br/>你好,世界!
34     <br/>你好,世界!
35     <br/>你好,世界!
36     <br/>你好,世界!
37     <br/>你好,世界!
38     <br/>你好,世界!
39     <br/>你好,世界!
40     <br/>你好,世界!
41     <br/>你好,世界!
42     <br/>你好,世界!
43     <br/>你好,世界!
44     <br/>你好,世界!
45 
46 </div>
47 
48 </body>
49 </html>
原文地址:https://www.cnblogs.com/sxz2008/p/7651804.html