The author touches the mobile front-end nearly a year, special will usually some of the notes sorted out, hoping to give the people who need some small help. At the same time, because the author's level is limited, although the author has encountered the use of, but the text may also appear some problems or not rigorous places, I hope you point out, greatly appreciated!
A. CSS section
- Body if set Height:100%;overflow:hidden is still can slide, if need to prohibit, add a layer div set height:100% plus Overflow:hidden (html,body plus height:100%) , so that the element cannot slide beyond the height of the body.
Or at the same time add Height:100%;overflow:hidden to Html,body.
META tags
<meta name= "viewport" content= "Width=device-width,initial-scale=1,user-scalable=no"/> Mobile plus this tag is really adaptive, Do not add, if you put a 980px width (mobile phone is 980) PC Web page on the phone display, can also be normal display does not appear scroll bar, but mobile device to the page has been reduced to optimize, so the font and so on are correspondingly reduced (980px is relative to the cell phone pixels, I have more than 1000px more of the scroll bar appears, this is not specific research).
About initial-scale=1, this reference iphone5 size 320*568, if you do the page according to 640*1136, scale is set to 0.5
<meta content= "yes" name= "apple-mobile-web-app-capable" > Safari in iOS allows full screen browsing
<meta content= "Black" name= "Apple-mobile-web-app-status-bar-style" > Safari top status bar style in iOS
<meta content= "Telephone=no" name= "format-detection" > Ignore turning numbers into phone numbers<meta content= "Email=no" name= "format-detection" > Ignore identification email
- Do full-screen display of the picture, generally in order to compatible with most of the mobile phone, the picture size is generally set to 640*960 (I think this size is good, also see a lot of pictures is this size, depending on the situation)
Remove the WebKit scroll bar
element::-webkit-scrollbar{
Display:none;
}
Remove the default style for button on iOS
-webkit-appearance:none;
border-radius:0
Do not want the button touch when there is a blue border-webkit-tap-highlight-color:rgba (0,0,0,0);
If you want to use fixed such as navigation and so on, you can achieve the same effect with absolute, the body is set to 100%, the element is absolute to the body, but this can not let the body scroll, if you need to scroll, put in the div scroll
Animation on the mobile side, if by changing the absolute positioning of the top, or margin to do the effect is very poor, very fluid, and the use of CSS3 transition or animation effect will be very good (this aspect of iOS than Android and much better).
If you use Translate3d to achieve animation, will turn on GPU acceleration, hardware configuration Poor Android use will consume performance, need to use caution (Borrow 1 floor reviews)
When using the picture, you will find that there is always about 4px blank under the picture (the reason is that the picture is inline, triggering baseline ...). ) Common solutions are
Img{display:block};
Img{vertical-align:top} also has several other values, depending on the situation
See this for other solutions
Learn to use the layout of Display:-webkit-box, can help us to do the page adaptive, such as the navigation bar these individuals feel particularly suitable, the specific use of the method is not described here
Use a tag, try to make a tag block, try to maximize the user clickable area
Two pages after using transform, the page under the Z-index sometimes will be invalid, I met, but not to seriously explore, just to improve the z-index, if you encounter this problem, detailed can see this
In iOS, when you click Input, such as input, the virtual keyboard pops up, the height of the entire window will be reduced to the height of the keyboard, adding you have fixed elements at the bottom such as btn, this element will run up, generally not too beautiful. I set it to absolute when I was a focus, depending on the situation.
Prevents users from selecting text-webkit-user-select:none
When you set input to width:100%, you may sometimes encounter input that is wider than the screen, and you can add an attribute to input Box-sizing:border-box
With regard to Box-sizing:border-box, this property is to include the high width of the border in the width of the box, if you set two elements float and 50%, and all have border, this property can be used to perfectly allow them to display on the same line
If the TD of the table is set to a width beyond the partially hidden words with col, the table plus attribute table-layout:fixed (fixed-width layout)
If you want to change the style in placeholder, you need to use CSS pseudo-class. For example::-webkit-input-placeholder{color: #ccc}
Two. js section
Mobile front-end notes-common JS and CSS problems encountered and how to solve them