Mobile REM settings, auto-change html<font-size>

Source: Internet
Author: User

<script>                (function (Doc, win) {                var docel = doc.documentelement,                resizeevt = ' Orientationchange ' in Window? ' Orientationchange ': ' Resize ',                recalc = function () {                var clientwidth = docel.clientwidth;                if (!clientwidth) return;                docEl.style.fontSize = * (clientwidth/320) + ' px ';            };            if (!doc.addeventlistener) return;            Win.addeventlistener (Resizeevt, Recalc, false);            Doc.addeventlistener (' domcontentloaded ', Recalc, false);            }) (document, window);     </script>

  

Add such a section of JS, you can dynamically change the width of the screen according to the Font-size

According to this sentence docEl.style.fontSize = (clientwidth/320) + ' px '; Know

iphone4 width is 320px, then Font-size is 20px, 100px is 5rem

Iphone6 width is 375px, then Font-size is 23.4375px,100px is 4.267rem

Package for red Rice mobile phone Xiaomi. Use media to query @media a bit of a pit. Some do not support so force the HTML to change the root dynamically according to the width of the screen by a section of JS

Mobile REM settings, auto-change html<font-size>

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.