Mobile-side page adaptation, REM layout

Source: Internet
Author: User

Mobile page Adaptation

EM calculates its own size based on the font size of the element itself.

REM Root EM calculates its own size based on the font size of the root node (HTML)

Adaptation: Each mobile device, the resolution size is inconsistent, so that our pages in various resolutions are displayed intact (equal to the scale);

Depending on the resolution of the screen

Dynamically set the font size of the HTML to achieve more than the zoom function of the page

Note: Ensure that the font size for the final HTML calculation cannot be less than 12

At the beginning of the first set up a section of JS code, to get the screen width, this JS precedence over any CSS and JS

<script>

(function () {

var html = document.queryselector ("html");

var width = html.getboundingclientrect (). width;

Html.style.fontSize = width/16 + "px";

WIDTH/16 html Font size = 16 of the screen width = 1rem

270/

Console.log (Html.getboundingclientrect ());

})();

</script>

Html.getboundingclientrect (). width; Get screen width

Pixel ratio

alert (window.devicepixelratio); Pixel ratio of 2 pixels to two pixels to display 1px of content

The width of the best design chart is maintained at 750 or more

Mobile-side page adaptation, 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.