Mobile phone-side page Adaptive Solution-rem Layout

Source: Internet
Author: User

Just introduce this native JS code to the page.

1234567891011121314151617 (function (doc, win) {       vardocEl = doc.documentElement,           resizeEvt = ‘orientationchange‘in window ? ‘orientationchange‘‘resize‘,           recalc = function () {               varclientWidth = docEl.clientWidth;               if (!clientWidth) return;               if(clientWidth>=640){                   docEl.style.fontSize = ‘100px‘;               }else{                   docEl.style.fontSize = 100 * (clientWidth / 640) + ‘px‘;               }           };       if (!doc.addEventListener) return;       win.addEventListener(resizeEvt, recalc, false);       doc.addEventListener(‘DOMContentLoaded‘, recalc, false);   })(document, window);

How do I use it?

This is the core code of the REM layout, the main idea of this code is:
If the width of the page is more than 640px, then the HTML in the page Font-size constant 100px, otherwise, the size of the HTML font-size in the page is: 100 * (Current page width/640)

Why is 640px?

The design diagram is generally 640px, so the equivalent of 100px = 1rem, can be easily calculated;

Because it is 640px, the size of the page should be limited, so the outermost box should be:

12345 position: relative;width: 100%;max-width: 640px;min-width: 320px;margin: 0 auto;

Mobile phone-side page Adaptive Solution-rem Layout

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.