Moving End page Unit rem

Source: Internet
Author: User
Tags definition end window

Today, a friend in the group uploaded a case, point into the study, found REM this unit.
Then I began to rem Baidu, found a few good articles, to share with you,

The following code is copied in a friend's case

<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<body>

</body>
<script>

Auto adaptation
var calculate_size = function () {
var base_font_size = 100;

var docel = document.documentelement,
ClientWidth = Docel.clientwidth;
if (!clientwidth) return;
DocEl.style.fontSize = Base_font_size * (clientwidth/320) + ' px ';
};

Abort If browser does not support AddEventListener
if (Document.addeventlistener) {
var resizeevt = ' orientationchange ' in window? ' Orientationchange ': ' Resize ';
Window.addeventlistener (Resizeevt, calculate_size, false);
Document.addeventlistener (' domcontentloaded ', calculate_size, false);
Calculate_size ();
}

</script>

About var base_font_size = 100;
explained as follows:
The value of the root element can be defined arbitrarily,
But the minimum definition of 20px is recommended,
Also have the definition of the time to consider the convenience of their own conversion,
Some people set 100px,
But don't define 10px,
Because Chrome does not support Chinese fonts less than 12px,
So it will cause when the calculation is less than 12px,
Will default to take 12px to calculate, resulting in the Chinese version of the REM calculation of chrome is inaccurate.

About ClientWidth
In Google browser phone mode test,
iphone4,5,6, shown as 980px,

ClientWidth Reference article:
Http://www.cnblogs.com/fullhouse/archive/2012/01/16/2324131.html
Http://www.cnblogs.com/kongxianghai/p/4192032.html


Supplementary about clientwidth/320
320 is no use.
Now it's usually 640, and 640 is a variable.
The design draft is generally 640px wide
If the designer gave you the design draft is 670px
Let's change 640 to 670.



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.