One, px em rem
px Pixels (Pixel). Relative length units. Pixel px is relative to the display screen resolution.
EM is the relative length unit. The font size relative to the text within the current object. If the font size of the current inline text is not artificially set, the default font size is relative to the browser. EM inherits the font size of the parent element.
REM is a new relative unit of CSS3 (root em, root em), and this unit has aroused widespread concern. What is the difference between this unit and EM? The difference is that when you use REM to set the font size for an element, it is still relative size, but relative to the HTML root element. This unit is a combination of relative size and absolute size of the advantages in one, through it can only modify the root elements in proportion to adjust all font size, but also to avoid the size of the font-layer composite chain reaction. Currently, in addition to IE8 and earlier versions, all browsers support REM. For browsers that do not support it, the workaround is simple enough to write an absolute unit statement. These browsers ignore font sizes that are set with REM.
For a variety of mobile devices, it is recommended to use REM, such as devices that only need to be adapted to different resolutions, such as iphone and ipad.
Perfect Fit Solution:
$ (function () {
Set REM
function Mobile () {
var size=100,//Specifies the conversion of the value between REM and px
MaxWidth = 750; Sets the datum width.
Ratio = function () {
var r = document.documentelement.clientwidth/maxwidth;
Return r>=1?1:r<=0.234?0.234:r;
};
set = function () {
Document.documentElement.style.fontSize = ratio () * size + ' px ';
}();
Window.onresize = Mobile;
}
Mobile ();
})
Second, Media Queries
Literal translation for the media query, in the CSS to write under different screens using different CSS to achieve screen adaptation, this way not only can be used to adapt the font, but also to achieve a different interface display different styles:
CSS to write a different screen range according to the requirements, as follows:
@media screen and (min-width:240px) and (max-width:750px) {
HTML {font-size:20px;}
}
Third, HTML code header add <meta>
H5 page window automatically adjusts to device width and prevents users from zooming the page
<metaName="viewport"content="Width=device-width,initial-scale=1.0,minimum-scale =1.0,maximum-scale=1.0,user-scalable=no "/>
Ignore numbers in a page as phone numbers
<metaName="format-detection"content="Telephone=no"/>
Ignore the recognition of email addresses in the Android platform
<metaName="format-detection"content="Email=no"/>
When the site is added to the home screen Quick Start mode, you can hide the address bar, only for iOS safari
<metaName="apple-mobile-web-app-capable"content="yes"/><!-- After the ios7.0 version, you can't see the effect on safari--
Add a website to the home screen Quick Start mode, only for iOS Safari top status bar style
<metaName="Apple-mobile-web-app-status-bar-style"content="Black"/> <!--optional default, black, black-translucent ---
|
Viewport templates Viewport template--general
<! DOCTYPE html><meta CharSet="Utf-8"><meta Content="Width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" Name="Viewport"><meta Content="Yes" Name="Apple-mobile-web-app-capable"><meta Content="Black" Name="Apple-mobile-web-app-status-bar-style"><meta Content="Telephone=no" Name="Format-detection"><meta content= "Email=no" Span class= "ATN" >name= "format-detection" > <title> title </title> <link rel= "stylesheet" href=><body> here start content </body> </HTML> |
Iv. use of percentages
To make the screen fit well, use a percentage as the value of the wide-high. This is usually used on CSS.
Cond......
HTML5 do WebApp Interface adaptation summary