Common precautions for mobile stations

Source: Internet
Author: User

I believe that many people who have just started to write mobile phone interface to face the problem of self-adaptation of the page, of course, a lot of solutions, such as: percent layout, flexible layout flex, responsive layout ... Here is the main introduction of my practice in the most comfortable with the simplest layout scheme, as well as some things to pay attention to. 1,head Inside Add code:
<name   content initial-scale  Maximum-scaleuser-scalable=no ">
(The H5 page window automatically adjusts to the device width and prevents users from scaling the page) This code explains several parameters: width = device-width: Widths equal to the width of the current device
Initial-scale: Initial zoom ratio (default = 1.0)
Minimum-scale: The minimum scale to allow the user to zoom (the default setting is 1.0)
Maximum-scale: Maximum scale allowed to be scaled by the user (default = 1.0)
User-scalable: Whether the user can zoom manually (the default is no, because we don't want the user to zoom out of the page) The first type of notation:
Html,body {font-size:} fong-size:1rem=16px of major mainstream browsers; This is the default browser; the back  layout follows the normal wording .

The second way of writing: REM layout is very simple, home you just need to introduce this piece of native JS code on the page can be
<script type= "Text/javascript" > (function(Doc, Win) {varDocel = doc.documentelement, resizeevt = ' Orientationchange 'inchWindow? ' Orientationchange ': ' resize ', Recalc =function() {varClientWidth = Docel.clientwidth;if(!clientwidth)return;if(clientwidth>=640) {docEl.style.fontSize = ' 100px ';}Else{docEl.style.fontSize = + * (clientwidth/640) + ' px ';} };if(!doc.addeventlistener)return; Win.addeventlistener (Resizeevt, Recalc,false); Doc.addeventlistener (' domcontentloaded ', Recalc,false); }) (document, window);</script>

This is the core code of the REM layout, the main idea of this code is:
If the width of the page is more than 640px, then the HTML in the page Font-size constant 100px, otherwise, the size of the page HTML font-size: 100 * (the current page width/640) 1, with REM layout, you need to set the html{ font-size:100px;}, and then px/100 2, in the REM layout, the distance between modules in the page is typically 0.2rem. Font size is generally divided into four grades 0.2rem, 0.24rem, 0.28rem, 0.32rem. 3, the background image tile Remember add: {background-size:100% 100%;} number can be set as required 4, the picture on the page: {width:100%; display:block;height:100%;} This is required to set 5, Width and height best Use 100% to do 6, with media queries to set the font size in different devices
A,     {} {} {} when the page width is greater than 800px and the height is greater than 400px, execute the CSS inside it

The third method can be used to do the elastic box model, the next chapter to explain

Common precautions for mobile stations

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.