3. Mobile Web for Base point

Source: Internet
Author: User

1. Mobile-screen adaptation

in the in WEB development , px (pixels), EM,pt(dots), in (inches), cm (cm) are used as length units, and we most commonly use px (pixels) as the unit of length.

We can divide the above-mentioned length units into relative length units and absolute length units. Inches is an absolute unit of length, and pixels are a relative unit of length.

Window.devicepixelratio ~= physical pixels / independent pixels

/Gets the physical pixel size of the screen

Window.screen.width;

Window.screen.height;

2. Viewport viewport;

get the size of the viewport

Document.documentElement.clientWidth;

Document.documentElement.clientHeight;

PC -side VIewport is not an HTML structure, so we can't change it through CSS, just the size of the browser window.

On mobile devices, viewport is no longer limited to browser windows, but rather allows developers to set the size of the viewport, usually the browser sets a default size of viewport, and in order to display those specifically designed for the PC Web page, This value is generally larger than the size of the screen.

<meta name= "viewport" content= "Width=device-width" >

<meta name= "viewport" content= "Width=device-width, initial-scale=1.0" >

Adaptation Program:

Adaptation Scheme 1

1, set <meta name= "viewport" content= "Width=device-width, initial-scale=1" >

2. Set the content area size to 320px

3. Set the content area horizontally centered display

Adaptation Scheme 2

1, set <meta name= "viewport" content= "Width=device-width, initial-scale=1" >

2. Set the page width as a percentage

Adaptation Scheme 3

1, set <meta name= "viewport" content= "Width=device-width, initial-scale=1" >

2. set the page element width unit to rem or em

Note: This scheme is flexible and our case will use this scheme

about the em and the REM

The EM relative length unit, which refers to the current element font size, and inherits its ancestor element font size if the current element does not have a font set for example . box {font-size:16px;} then 1em = 16px. box {font-size:32px;} the 1em = 32px , 0.5em = 16px

REM relative length unit, which refers to the root element (HTML) font size such as HTML {font-size:16px;} the 1rem = 16px html {font-size:32px;} the 1rem = 32px ,  0.5rem = 16px; Note: All browsers default font size is 16px ( Some Android phones can adjust the system font size, the browser default font size will be affected)

Adaptation Scheme 4

1. Set Web page width equal to device physical pixel

2. Set the initialization scale (value 1 /Window.devicepixelratio)

3. About Media enquiries

Syntax format

A) HTML method

<link href= "./css/phone.css" media= "only screen and (min-width:320px) and (max-width:640px)" >

3. Mobile Web for Base point

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.