WebApp ideas and REM adaptation are extremely viewport

Source: Internet
Author: User

WebApp in the production time, the page to add the viewport tag, used for adaptation;

Viewport meta tag, refers to when the mobile side of the display, viewport is how big? Mobile Browser is the screen width, viewport general (mobile browser) default is about 960px, the page compression to

960px display, so is wider than the mobile phone screen yo. So, in order to show the good looks, to set viewport for screen width, is: So label

<meta name="viewport" content="width=device-width,initial-scale=1.0, Maximum-scale=1.0,user-scalable=no">

Set the width to the device, and then scale the page size so large. So, in many cases, in the WebApp page, we directly in the PC-side test on the line, directly design 640px width to do, and then the HTML and body

Width is set to 100%, the main container width is 640px, and then, suitable for the mobile phone side, it will be slightly compressed display on the phone's viewport, about the same, and, in addition to REM adaptation, generally no problem.

The REM adaptation, which is based on the root element of HTML, 1rem is the font size of the root element. If you set it to 10px, then 1rem is 10px, and then all is expressed in rem, and then, in JavaScript or CSS, media Query to implement HTML fonts that are not allowed on different screens, and then all the rest will follow this proportional change. That's the principle.

Speaking, is actually two points: the role of 1,viewport, 2,rem to adapt, of course, also useful 100% ratio, but out of the

Lists the test successful REM-fit CSS and JS code:

Css:

@media only screen and (max-width:320px) {html{font-size:9px;} } @media only screen and (min-width:320px) and (max-width:352px) {html{font-size:10px;} } @media only screen and (min-width:352px) and (max-width:384px) {html{font-size:11px;} } @media only screen and (min-WIDTH:384PX) and (max-width:416px) {html{font-size:12px;} } @media only screen and (min-WIDTH:416PX) and (max-width:448px) {html{font-size:13px;} } @media only screen and (min-width:448px) and (max-width:480px) {html{font-size:14px;} } @media only screen and (min-width:480px) and (max-width:512px) {html{font-size:15px;} } @media only screen and (min-width:512px) and (max-width:544px) {html{font-size:16px;} } @media only screen and (min-WIDTH:544PX) and (max-width:576px) {html{font-size:17px;} } @media only screen and (min-WIDTH:576PX) and (max-width:608px) {html{font-size:18px;} } @media only screen and (min-width:608px) and (max-width:640px) {html{font-size:19px;} } @media only screen and (min-width:640px) {html{font-size:20px;}}

ls|

(function (Doc, win) {varDocel =doc.documentelement,resizeevt='Orientationchange' inchWindow?'Orientationchange':'Resize', Recalc=function () {varClientWidth =Docel.clientwidth;if(!clientwidth)return;if(clientwidth>640) {clientwidth=640;}//This line of code is fraudulent, 10 change to a smaller number, such as 5, there is no response ... Word size yes, but//Div's width is not changed, it's drunk.DocEl.style.fontSize =Ten* (ClientWidth/ the) +'px';};if(!doc.addeventlistener)return; Win.addeventlistener (resizeevt, Recalc,false);d Oc.addeventlistener ('domcontentloaded', Recalc,false);}) (document, window);

WebApp ideas and REM adaptation are extremely viewport

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.