Mobile REM Use

Source: Internet
Author: User

<!-- rem CSS3 A new relative unit, relative to the root node (HTML) font size value roothtml{font-size:10px}    2rem=20px can only modify the size of the root element, you can proportionally adjust all the font size , relying only on the size of the HTML font-- 

first way: Multi-resolution setting REM settings (different resolutions in different sizes, such as IPhone6, 1rem=23px)

/*Note3*/@media only screen and (min-width:360px){html{font-size:22px!important;}}/*IPhone6*/@media only screen and (MIN-WIDTH:376PX){html{font-size:23px!important;}}/*IPhone6 plus*/@media only screen and (min-width:414px){html{font-size:25px!important;}}/*Big Resolution*/@media only screen and (min-width:641px){html{font-size:25px!important;}}

The second way: JS implementation, such as your plan is 1080px, then you use 1080/18=60px,1rem=60px

  REM Layout 1, must be dynamic to set the size of the HTML, in order to fit 2, according to the page (note: Is the PSD graph, that is, the real size of large) divided by a factor, the calculated value assigned to the HTML font-size attribute 1, why to divide a number, the reason is: a page, It is not possible to have all the elements of the entire screen, there must be multiple elements in a row. So the line is divided into N 2, not apart from a number, that 1 REM is the width of the screen, the value is too large, if an element is smaller than its width, it is not convenient to calculate 3, the coefficient, self-determined. It is possible, but it is recommended to give a value divisible by the characteristics: 1, all units of the property will automatically calculate the size according to the size of the screen 2, the same element, the size of the different devices are not the same. Small display under the size of the device, the large size of the device display 3, the general Iphone6 as the benchmark, with its width 750 in addition to the previous factor, then to calculate the REM  --> 
<script>            (function() {                var html=document.documentelement;                 var width=Html.getboundingclientrect (). width;//Gets the window size                                html.style.fontSize=width/18+ ' px ';                                // The design figure is 1080px 1rem=60             })(); </script>

Mobile REM Use

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.