移動端布局注意事項及解決

來源:互聯網
上載者:User

標籤:min   大寫   比例   media   背景   can   定位   網站   sha   

1.winphone系統a、input標籤被點擊時產生的半透明灰色背景怎麼去掉

<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、忽略頁面的數字為電話,忽略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高亮效果

在做移動端頁面時,會發現所有a標籤在觸發點擊時或者所有設定了偽類 :active 的元素,預設都會在啟用狀態時,顯示高亮框,如果不想要這個高亮,那麼你可以通過css以下方法來禁止:

.xxx {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}


8、如何禁止儲存或拷貝映像

通常當你在手機或者pad上長按映像 img ,會彈出選項 儲存映像 或者 拷貝映像,如果你不想讓使用者這麼操作,那麼你可以通過以下方法來禁止:

img {
-webkit-touch-callout: none;
}
PS:需要注意的是,該方法只在 iOS 上有效。



9、解決字型在移動端比例縮小後出現鋸齒的問題:

-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、按鈕被按下效果的實現需要給a標籤加a:active屬性和添加一段空函數

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%;而且不能添加高度。



18. 移動端如何清除輸入框內陰影

在iOS上,輸入框預設有內部陰影,但無法使用 box-shadow 來清除,如果不需要陰影,可以這樣關閉:

input,
textarea {
border: 0;
-webkit-appearance: none;
}
19. 移動端禁止選中內容

如果你不想使用者可以選中頁面中的內容,那麼你可以在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控制項預設面板醜陋



22. 消除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加速

**************************************************************************

架構

1. 移動端基礎架構


zepto.js 文法與jquery幾乎一樣,會jquery基本會zepto~

iscroll.js 解決頁面不支援彈性滾動,不支援fixed引起的問題~ 實現下拉重新整理,滑屏,縮放等功能~

underscore.js 該庫提供了一整套函數式編程的實用功能,但是沒有擴充任何JavaScript內建對象。

fastclick 加快移動端點擊回應時間

animate.css CSS3動畫效果庫

Normalize.css Normalize.css是一種現代的、CSS reset為HTML5準備的優質替代方案


2. 滑屏架構

適合上下滑屏、左右滑屏等滑屏切換頁面的效果

slip.js

iSlider.js

fullpage.js

swiper



3.瀑布流架構

masonry

工具推薦

caniuse 各瀏覽器支援html5屬性查詢

paletton 調色搭配



對於網站字型設定

移動端項目:

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;(數字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);

}


針對適配等比縮放的方法:

@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;}
}

移動端布局注意事項及解決

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.