Mobile uses JS to control the use of font size with REM

Source: Internet
Author: User

Through JS to control the page font size, directly on the code:

(functionvarvarfunctionvar fontSize = $ (window).) width () < 640? $ ( window). Width ()/16:40; Roothtml.css ("Font-size", fontSize); } rootresize (); $ (window). Resize (function() {rootresize ();}); })();

Next you can specify the size of the font-size directly in the page root element, so that you can control the overall page text size adaptive

Body {width:16rem; margin:0 Auto; background-color: #fff; font-size:. 6rem; color:#000;}

Finally, summarize the CSS common styles in the page:

*{-webkit-box-sizing:Border-box;-moz-box-sizing:Border-box;box-sizing:Border-box;margin:0;padding:0;}
body,form,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,p{margin:0;padding:0;}
Div,ul,dl,dt,dd,p,h1,h2,h3,h4,h5,h6{Zoom:1;}
Body{font-family:' Microsoft Yahei ';
/*-webkit-user-select:none;*/
-webkit-text-size-adjust:None;Background-color:#fff;}
Input,select{Line-height:Normal;vertical-align:Middle;}
textarea{font-size:1em;Line-height:1.5em;}
a{text-decoration:None;Color:#000;Outline:0;}
a:visited{text-decoration:None;}a:hover{text-decoration:None;}
IMG{Border:0;Max-width:100%;}Li,ul{List-style:None;}
Body{width:16rem;margin:0 Auto;Background-color:#fff;font-size:. 6rem;Color:#000;}
. Hidden{Display:None;}. Clear{Clear:both;}. CL{Clear:both;}. Zleft{float: Left;}. Zright{float: Right;}
. Zmore{Color:#771d0e!important;}. Zblock{Display:Block;}. zred{Color:red!important;}/*compatible with Apple*/
Input{-webkit-appearance:None;/*Remove input Default style*/}input[type= ' Radio ']{-webkit-appearance:Radio;}input[type= ' submit '],input[type= ' Reset '],input[type= ' button '],input{-webkit-appearance:None;}/*compatible Apple End*/

These are the usual CSS styles that are required for a person to write a mobile page.

Mobile uses JS to control the use of font size with REM

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.