Mobile-side adaptation knowledge grooming

Source: Internet
Author: User

Understand the knowledge of the mobile side

Viewport
Viewport is the viewable area of the user's Web page. The mobile browser is to put the page in a virtual "window" (viewport), usually this virtual "window" (viewport) wider than the screen, so that you do not have to squeeze each page into a very small window (this will destroy the layout of the page without the optimization of the mobile browser), Users can view different parts of a Web page by panning and zooming.


Pixel
The pixels in the CSS are just an abstract unit, the earlier cell phone screen has a lower pixel density, and a css pixel equals a physical pixel. But as the phone's screen pixel density is increasing, such as retina, the same size of the phone, the resolution is increased by more than one, which means that the same size of the screen, the pixel more than one time, when a CSS pixel is equal to two physical pixels.
In the mobile browser, the Window object has a DPR property (the ratio of the physical pixels of the device to the device's independent pixels), that is, dpr= the physical pixels/independent pixels, so in the retina screen, dpr=2, look at the picture.

Meta
When developing on the mobile side, we need to add a sentence to the head<meta name="viewport" content="width=device-width, initial-scale=1.0">

      • Width: Controls the size of the viewport, a value that can be specified, or a special value, such as device-width as the width of the device (in units of CSS pixels scaled to 100%).

      • Height: corresponds to width, specifying height.

      • Initial-scale: The initial zoom ratio, which is the scale at which the page is first load.

      • Maximum-scale: Allows the user to zoom to the maximum scale.

      • Minimum-scale: The minimum scale to which the user is allowed to zoom.

      • User-scalable: Whether the user can scale manually.

Several solutions for mobile-side adaptation

Rem
REM refers to the unit of font size relative to the root element, and we can control the size of REM by setting the font size of the HTML.
It should be noted that the size of the font does not use REM, we can do the corresponding treatment according to different DPR.


Method One
CSS3 media can be used to query the @media, this method can be adapted to the majority of models.

HTML{font-size:20px;}@media only screen and (min-width:401px){HTML {font-size:25px!important; }} @media only screens and (min-width:428px){HTML {font-size:26.75px!important; }} @media only screens and (min-width:481px){HTML {font-size:30px!important; }} @media only screens and (MIN-WIDTH:569PX){HTML {font-size:35px!important; }} @media only screens and (min-width:641px){HTML {font-size:40px!important; }}

Method Two
Want to achieve multi-terminal adaptation, here recommended hand Amoy Team Lib-flexible Library, concrete implementation method can refer to https://github.com/amfe/artic ...


Method Three
CSS3 's new unit VW,VH. 1VW equals the visible area width (the viewable area of the screen is the layout area) of 1%, and 1VH equals 1% of the visible area height. Unfortunately this unit is still a lot of browsers do not support.

At present I know the method of these few, if there is hope that you can add.

Mobile-side adaptation knowledge grooming

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.