Looking back, the mobile Web page code writing is far less complex than I thought (probably because I did this project for the sake of simplicity). But in terms of getting started, it's actually pretty simple, and I've summed him up in a few ways: special META tags/hundred percent layout width/rem set font size/CSS3 use. OK, let's get started, here is the humble opinion of the mobile web novice, the birds, please detour, if you are grateful. 1. Special meta tags; since the browsers for our smartphones (ios,android) are based on the WebKit kernel, there are a few special meta tags for webkit that play an important role in developing the mobile Web:<Metacontent= "Width=device-width,Initial-scale=1.0,Maximum-scale=1.0,user-scalable=0; "name= "Viewport"/>Forces the width of the document to remain at 1:1 of the width of the device, and the maximum width of the document is 1.0, and does not allow the user to click on the screen to enlarge;<Metacontent= "Yes"name= "Apple-mobile-web-app-capable"/>the safari private meta tag in the iphone device, which says: Allow full screen mode to browse;<Metacontent= "BLACK"name= "Apple-mobile-web-app-status-bar-style"/>The iphone's private label, which specifies the style of the iphone's status bar on the top of safari;<Metacontent= "Telephone=no"name= "Format-detection"/>tells the device to ignore numbers in the page as phone numbers. <Metacontent= "Email=no"name= "Format-detection"/>The email address on the page is not automatically recognized in Android, and the email address is not automatically recognized in iOS (note: Because WebKit's browser is better for HTML5 support, it is best to use HTML5 when declaring the header. Of course if you are accustomed to HTML4, then I can only tell you, or to learn HTML5 in the next look! 2. The layout of the design of the designer 640px (design draft by IPHONE4), I set the height/size of each module strictly according to the design draft. The next sad thing happened, the page written out on the mobile phone shows an unusually large. I'm a fool, this is the case! Consulting professionals later learned that although the resolution of the iphone4 is 960x640px, its screen pixel density is relatively high, its actual size should be halved. So when writing code, all height/size is 1/2 of the design draft. And then the percent layout: when you do a mobile Web page, we use a percent layout to achieve the adaptive screen width. With PC-side web page development experience, students will know that the elements of the box model (unclear students can go to W3school on the search). So I want an element 100% display, and must have a fixed padding-left/padding-right, and a 1px border, how to do? element{width:100%; padding-left:10px; BORDER:1PX solid Blue;} So writing code will inevitably result in a horizontal scroll bar, swollen? Believe that the problem is to be solved. At this time the great CSS3 for us to provide the Box-sizing property, the specific explanation of this property do not repeat (want to learn more about the students can go to W3school to see, to know that their hands will be easier to remember). Let's see how to solve the above problem: element{width:100%; padding-left:10px; Box-sizing:border-box; -webkit-box-sizing:border-box; BORDER:1PX solid Blue;} OK, the problem is solved! 3. rem to set the font size; Here's a few things we can do to comb the CSS: Px/em/rem (The following excerpt from the 0101 backyard) PX: is the most basic length of the CSS unit, with PX to do the unit basically no problem, to make the page according to the precise presentation of the routine. But, (when you hear it, it's suddenly uncomfortable, like every timeThe development of the students shout me, my subconscious will tell myself, bad again out of the bug!! If the entire PX layout will hide a problem, that is, when the user and Ctrl roll the page (plainly, ctrl+,ctrl-), you will find that the page structure produced unpredictable confusion, so there are bricks advocate using em instead of PX. Em:em is the relative unit, and EM relative to the reference point is the browser font size (the browser default font is 16PX), so 1em default equals 16px. So 14px=0.875em; The formula is 14/16=0.875em. If you write with EM, you can solve the problem of page confusion caused by ctrl+,ctrl-. However, the problem again, EM accurate is relative to the parent node's font size to calculate, if you define the font size then relative to the size of their own calculation, such as: HTML {font-size:100%;}. box-0 {height:1em;/* At this time height equals 16px */}.box-1 {font-size:0.625em;/* The base font size is changed to 16*0.625=10px */height:1em; /* At this time the actual height is equal to 10px */} See understand, 1em is not a fixed value, coupled with mathematics is taught by P.E. teacher, this is not self-inflicted. It doesn't matter, CSS3 to introduce a new unit for us is REM can solve this problem. Rem:rem and EM are also a relative unit, in order to facilitate understanding, we understand rem as root em, as the name implies REM only relative to the node<HTML>Calculation, this means that as long as the root node set a good reference value, then the entire 1rem are equal, the calculation method with EM, the default 1rem=16px; In the same vein you can set the HTML {font-size:62.5%} so 1rem is equal to 10px, etc... (Of course, the ie678 don't support REM, but fortunately we're doing a mobile Web page) 4. Use CSS3, how to do such a large mobile Web page can be less CSS3. But usually CSS3 use less, here note a few I use in this project CSS3 attribute. More in-depth parents to learn their own. Similarly, here do not repeat the attributes, put a strong w3school do not, I can only say to you: medicine can not stop AH! : A. Rounded corners (this is too common) element{border:1px solid blue; -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px;} B. Gradients (this is often used when making buttons) element{Background-image:-moz-linear-gradient (Top, #2288cc, #389de2);/* Firefox */back Ground-image:-webkit-gradient (linear, left top, left bottom, color-stop (0, #389de2), Color-stop (1, #2288cc)); /* saf4+, Chrome */}c. Remove the transparent layer that appears when you click on a handheld device (typically formatted in the head) a,button,input{-webkit-tap-highlight-color:rgba (0,0,0,0); -webkit-tap-highlight-color:transparent; /* For some androids */} When this property is applied, the active property of the link is effective, and the workaround is to run Document.addeventlistener ("Touchstart", function, unload when the page is () {}, True); Make the active state available. (Note: Under the Xiaomi System, click the link will still appear red border, if you have a solution, please enlighten, appreciate. ) DChange the box model (as already mentioned above) element{Box-sizing:border-box; -webkit-box-sizing:border-box;} 5. About commissioning; Well, with the knowledge above, we can write a moving page. But don't be too optimistic, how do we debug it? Do you send a server every time you write a page, and then use your phone to access the test environment! Of course, it does not need to be so troublesome, if the classmate with a PC, you can use a local localhost tool debugging (this time you do not have to do their own, with my own tools.) The usage is simple, put all the pages into a folder, the page is placed in the root directory, the tool is also placed in the directory, the page you want to debug to index.html. Of course, if you have several pages, it is best to make an index page. Start the debugger, use your phone to access your computer's IP, to ensure that the phone uses WiFi and PC network in a Web segment). With the Friends of the Mac on the Internet to find a way to configure the localhost, to open the following this feature can be accessed.
The things on the mobile side