移動端網(wǎng)頁布局中需要注意事項以及解決方法總結,這份對我們在布局移動端網(wǎng)頁的時候非常有用!
winphone系統(tǒng)a、input標簽被點擊時產(chǎn)生的半透明灰色背景怎么去掉
<meta name="msapplication-tap-highlight" content="no">
1、關閉iOS鍵盤首字母自動大寫<input type="text" autocapitalize="off" />
2、禁止文本縮放html {-webkit-text-size-adjust: 100%;}
3、移動端如何清除輸入框內陰影在iOS上,輸入框默認有內部陰影,但無法使用 box-shadow 來清除,
如果不需要陰影,可以這樣關閉:input,textarea {border: 0;-webkit-appearance: none;}
4、忽略頁面的數(shù)字為電話,忽略email識別<meta name="format-detection" content="telephone=no, email=no"/>
5、快速回彈滾動.xxx {overflow: auto;-webkit-overflow-scrolling: touch;}
PS:iScroll用過之后感覺不是很好,有一些詭異的bug,這里推薦另外一個 iDangero Swiper,這個插件集成了滑屏滾動的強大功能(支持3D),而且還有回彈滾動的內置滾動條,
官方地址:http://www.idangero.us/sliders/swiper/index.php
6、移動端禁止選中內容div {-webkit-user-select: none;}
7、移動端取消touch高亮效果在做移動端頁面時,會發(fā)現(xiàn)所有a標簽在觸發(fā)點擊時或者所有設置了偽類 :active 的元素,默認都會在激活狀態(tài)時,顯示高亮框,如果不想要這個高亮,那么你可以通過css以下方法來禁止:.xxx {-webkit-tap-highlight-color: rgba(0, 0, 0, 0);}
8、如何禁止保存或拷貝圖像通常當你在手機或者pad上長按圖像 img ,會彈出選項 存儲圖像 或者 拷貝圖像,如果你不想讓用戶這么操作,那么你可以通過以下方法來禁止:img {-webkit-touch-callout: none;}PS:需要注意的是,該方法只在 iOS 上有效。
9、解決字體在移動端比例縮小后出現(xiàn)鋸齒的問題:-webkit-font-smoothing: antialiased;
10、柵格布局:box-sizing:border-box;可以改變盒子模型的計算方式方便你設置寬進行自適應流式布局
11、input[type=input]{-webkit-appearance:none;}移除ios的樣式,但這個屬性存在bug,會導致iso無法獲取checkbox值,給這個元素重新賦上input[type=checkbox]{-webkit-appearance:checkbox;}就不會報錯了。
12、按鈕被按下效果的實現(xiàn)需要給a標簽加a:active屬性和添加一段空函數(shù)document.body.addEventListener('touchend', function () { });
13、解決去掉下邊框:-webkit-border-bottom:none;
14、英文文本換行(不拆分單詞):word-wrap:break-word
15、字體大小盡量使用pt或者em,rem,代替px。
16、設置input里面placeholder字體的大小::-webkit-input-placeholder{ font-size:10pt;}
17、wap頁面有img標簽,記得加上display:block;屬性來解決img的邊緣空白間隙的1px像素。如果圖片要適應不同的手機要設置width:100%;而且不能添加高度。
移動端如何清除輸入框內陰影在iOS上,輸入框默認有內部陰影,但無法使用 box-shadow 來清除,如果不需要陰影,可以這樣關閉:input,textarea {border: 0;-webkit-appearance: none;}
移動端禁止選中內容如果你不想用戶可以選中頁面中的內容,那么你可以在css中禁掉:.user-select-none {-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;}兼容IE6-9的寫法:onselectstart="return false;" unselectable="on"
20.audio元素和video元素在ios和andriod中無法自動播放應對方案:觸屏即播$('html').one('touchstart',function(){audio.play()})
21.手機拍照和上傳圖片<input type="file">的accept 屬性<input type=file accept="image/"><input type=file accept="video/">ios 有拍照、錄像、選取本地圖片功能部分android只有選取本地圖片功能winphone不支持input控件默認外觀丑陋
- 消除transition閃屏.css{-webkit-transform-style: preserve-3d;-webkit-backface-visibility: hidden;}
23.開啟硬件加速解決頁面閃白保證動畫流暢.css {-webkit-transform: translate3d(0, 0, 0);-moz-transform: translate3d(0, 0, 0);-ms-transform: translate3d(0, 0, 0);transform: translate3d(0, 0, 0);}
設計高性能CSS3動畫的幾個要素盡可能地使用合成屬性transform和opacity來設計CSS3動畫,不使用position的left和top來定位利用translate3D開啟GPU
加速**************************************************************************框架
移動端基礎框架zepto.js 語法與jquery幾乎一樣,會jquery基本會zepto~iscroll.js 解決頁面不支持彈性滾動,不支持fixed引起的問題~ 實現(xiàn)下拉刷新,滑屏,縮放等功能~underscore.js 該庫提供了一整套函數(shù)式編程的實用功能,但是沒有擴展任何JavaScript內置對象。
fastclick 加快移動端點擊響應時間
animate.css CSS3動畫效果庫
Normalize.css Normalize.css是一種現(xiàn)代的、CSS reset為HTML5準備的優(yōu)質替代方案滑屏框架適合上下滑屏、左右滑屏等滑屏切換頁面的效果slip.jsiSlider.jsfullpage.jsswiper
3.瀑布流框架masonry工具推薦caniuse 各瀏覽器支持html5屬性查詢paletton 調色搭配對于網(wǎng)站字體設置移動端項目:font-family:Tahoma,Arial,Roboto,"Droid Sans","Helvetica Neue","Droid Sans Fallback","Heiti SC",sans-self;
移動和pc端項目:font-family:Tahoma,Arial,Roboto,"Droid Sans","Helvetica Neue","Droid Sans Fallback","Heiti SC","Hiragino Sans GB",Simsun,sans-self;有關Flexbox彈性盒子布局一些屬性不定寬高的水平垂直居中
.xxx{position:absolute;top:50%;left:50%;z-index:3;-webkit-transform:translate(-50%,-50%);border-radius:6px;background:#fff;}[flexbox版]不定寬高的水平垂直居中
.xx{justify-content:center;//子元素水平居中,
align-items:center;//子元素垂直居中;
display:-webkit-flex;}
//單行文本溢出.xx{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}
多行文本溢出.xx{display:-webkit-box !importmort;overflow:hidden;text-overflow:ellipsis;word-break:break-all;-webkit-box-orient:vertical;-webkit-line-clamp:2;(數(shù)字2表示隱藏兩行)}
使用流體圖片img{width:100%;height:auto;width:auto\9;}
一像素邊框(例子:移動端列表的下邊框)
.list-iteam:after{position: absolute;left: 0px;
right: 0px;content: '';
height: 1px;transform: scaleY(0.5);
-moz-transform: scaleY(0.5);
-webkit-transform:scaleY(0.5);
background-color: #e3e3e3;}
針對適配等比縮放的方法:
@media only screen and (min-width: 1024px){body{zoom:3.2;}}
@media only screen and (min-width: 768px) and (max-width: 1023px) {body{zoom:2.4;}}
@media only screen and (min-width: 640px) and (max-width: 767px) {body{zoom:2;}}
@media only screen and (min-width: 540px) and (max-width: 639px) {body{zoom:1.68;}}
@media only screen and (min-width: 480px) and (max-width: 539px) {body{zoom:1.5;}}
@media only screen and (min-width: 414px) and (max-width: 479px) {body{zoom:1.29;}}
@media only screen and (min-width: 400px) and (max-width: 413px) {body{zoom:1.25;}}
@media only screen and (min-width: 375px) and (max-width: 413px) {body{zoom:1.17;}}
@media only screen and (min-width: 360px) and (max-width:374px) {body{zoom:1.125;}}