Mobile H5 page Self-adapting phone screen width

Source: Internet
Author: User

1. Because I am using sublime.text, I can achieve the effect with REM.

Click Browse Packages under Preferences in the menu, select Cssrem-master, add or write Cssrem.sublime-settings file.

Set the value of Px_to_rem to 75.

Enter the corresponding PX value of the setting in the code and press the TAB key to convert to REM

When used, a colleague references a flexible.js file

2.<meta name= "apple-mobile-web-app-capable" content= "yes" >

Not in the following ()

(using meta tags , which is also a popular method, in theory, the use of this label can be adapted to all sizes of the screen, but the device to explain the way the label and the degree of support is not compatible with all browsers or systems.)

First explain the meaning of the label: <meta name= "viewport" content= "width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, User-scalable=no "/>

If you completely do not understand the use of this label need to first Baidu a bit.

Explanation: Content of "width" This width refers to what breadth, I read the article on this is not explained very clearly, there are several alternatives: the width of the virtual window, the width of the phone screen, or the width of the page, and so on? By experiment this refers to the width of the virtual window. After understanding the width, to follow the various scales, you should know who is the proportion of the virtual window width/page width, so there will be a problem with Android device size difference is very large light mainstream has a width of 320 480 720 1080 a variety of dimensions and the above label can only support one size, Of course some browsers will automatically zoom to adapt to the screen, but this is not a unified standard, the correct way is to use JS dynamic generation of this tag , of course, you should first get the screen size. )

<script type= "Text/javascript" >
if (/android (\d+\.\d+)/.test (navigator.useragent)) {
var version = parsefloat (regexp.$1);
if (version>2.3) {
var Phonescale = parseint (window.screen.width)/640;
document.write (' <meta name= ' viewport "content=" width=640, Minimum-scale = ' + Phonescale + ', Maximum-scale = ' + phoneSc Ale + ', target-densitydpi=device-dpi ' > ');
}else{
document.write (' <meta name= ' viewport "content=" width=640, target-densitydpi=device-dpi ">");
}
}else{
document.write (' <meta name= ' viewport "content=" width=640, User-scalable=no, target-densitydpi=device-dpi ">") ;
}
</script>

3. Share the <script src= "Http://res.wx.qq.com/open/js/jweixin-1.0.0.js" to be referenced ></script>

4. Use media query features such as iphone compatible style @media only screen and (min-device-width:320px) and (max-device-height:460px) {}

To do the above, the basic self-adaptation can be

Mobile H5 page Self-adapting phone screen width

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.