移动端页面开发遇到的一些问题

1、meta 标签的相关知识

一、移动端页面设置视口宽度等于设备宽度,并禁止缩放css

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
复制代码

二、移动端页面设置视口宽度等于设备宽度,并禁止缩放,经常使用于微信浏览器页面。html

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
复制代码

三、禁止将页面中的数字识别为电话号码android

<meta name="format-detection" content="telephone=no" />
复制代码

四、忽略 Android 平台中对邮箱地址的识别ios

<meta name="format-detection" content="email=no" />
复制代码

五、当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅针对 ios 的 safariweb

<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- ios7.0版本之后,safari上已看不到效果 -->
复制代码

六、将网站添加到主屏幕快速启动方式,仅针对 ios 的 safari 顶端状态条的样式api

<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 可选default、black、black-translucent -->
复制代码

viewport 模板浏览器

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />
    <title>title</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    content...
  </body>
</html>
复制代码

2、CSS 的样式技巧

一、禁止 iosandroid 用户选中文字微信

.css { -webkit-user-select:none }
复制代码

二、禁止 ios 长按时触发系统的菜单,禁止 ios & android 长按时下载图片app

.css { -webkit-touch-callout: none }
复制代码

三、webkit 去除表单元素的默认样式ide

.css { -webkit-appearance:none; }
复制代码

四、修改 webkit 表单输入框 placeholder 的样式

input::-webkit-input-placeholder{
  color: #aaa;
}

input:focus::-webkit-input-placeholder{
  color: #eee;
}
复制代码

五、去除 android a/button/input 标签被点击时产生的边框 & 去除 ios a 标签被点击时产生的半透明灰色背景

a,button,input {
  -webkit-tap-highlight-color:rgba(255,0,0,0);
}
复制代码

六、ios 使用 -webkit-text-size-adjust 禁止调整字体大小

body {
  -webkit-text-size-adjust: 100%!important;
}
复制代码

七、android 上去掉语音输入按钮

input::-webkit-input-speech-button {
  display: none;
}
复制代码

八、移动端定义字体,移动端没有微软雅黑字体

/* 移动端定义字体的代码 */ 
body {
  font-family:Helvetica;
}
复制代码

3、其余问题

一、手机拍照和上传图片

<!-- 选择照片 -->
<input type=file accept="image/*">

<!-- 选择视频 -->
<input type=file accept="video/*">
复制代码

二、取消 input 在ios下,输入的时候英文首字母的默认大写

<input autocapitalize="off" autocorrect="off" />
复制代码

三、打电话和发短信

<a href="tel:0100-100000">打电话给:0100-100000</a>

<a href="sms:10086">发短信给: 10086</a>
复制代码

4、CSS reset

@charset "utf-8";
html{
  -webkit-text-size-adjust:none;
  -webkit-user-select:none;
  -webkit-touch-callout: none;
  font-family: Helvetica;
}
body{font-size:12px;}
body,h1,h2,h3,h4,h5,h6,
p,dl,dd,ul,ol,pre,form,
input,textarea,th,td,select{
  margin:0; 
  padding:0; 
  font-weight: normal;
  text-indent: 0;
}
a,button,input,
textarea,select{ 
  background: none; 
  -webkit-tap-highlight-color:rgba(255,0,0,0); 
  outline:none; 
  -webkit-appearance:none;
}
em{
  font-style:normal
}
li{
  list-style:none
}
a{text-decoration:none;}
img{
  border:none; 
  vertical-align:top;
}
table{
  border-collapse:collapse;
}
textarea{ 
  resize:none; overflow:auto;
}
 
复制代码

Normalize.css是一种 CSS reset的替代方案。它在默认的 HTML 元素样式上提供了跨浏览器的高度一致性。相比于传统的CSS resetNormalize.css是一种现代的、为HTML5准备的优质替代方案。

Normalize.css的传送门

5、经常使用公用 CSS style

/* 清除浮动 */
.clear { zoom:1; }
.clear:after { 
  content: ''; 
  display: block;
  clear: both;
}
 
/* 定义盒模型为怪异和模型(宽高不受边框影响) */
.boxSiz{
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
  box-sizing: border-box;
}
 
/* 强制换行 */
.toWrap{
  /* 只对英文起做用,以字母做为换行依据。 */
  word-break: break-all;
  /* 只对英文起做用,以单词做为换行依据。*/
  word-wrap: break-word;
  /* 只对中文起做用,强制换行。*/
  white-space: pre-wrap;
}
 
/* 禁止换行 */
.noWrap{
  white-space: nowrap;
}
 
/* 禁止换行,超出省略号 */
.noWrapEllipsis{
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis;
}
 
/* 文字两端对齐 */
.text-justify{
  text-align: justify;
  text-justify: inter-ideograph;
}
 
/* 定义盒模型为 flex布局兼容写法并让内容水平垂直居中 */
.flex-center{
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -o-box;
  display: box;
  -webkit-box-pack: center;
  -moz-box-pack: center;
  -ms-flex-pack: center;
  -o-box-pack: center;
  box-pack: center;
  -webkit-box-align: center;
  -moz-box-align: center;
  -ms-flex-align: center;
  -o-box-align: center;
  box-align: center;
}
复制代码

6、flex弹性布局

一、定义弹性盒模型兼容写法

/* box inline-box */
.css {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -o-box;
  display: box;
}
复制代码

二、box-orient 定义盒模型内伸缩项目的布局方向

/** * vertical column 垂直 * horizontal row 水平 默认值 */
.css {
  -webkit-box-orient: horizontal;
  -moz-box-orient: horizontal;
  -ms-flex-direction: row;
  -o-box-orient: horizontal;
  box-orient: horizontal;
}
复制代码

三、box-direction 定义盒模型内伸缩项目的正序(normal默认值)、倒叙(reverse)

/* Firefox */
.css {
  display: -moz-box;
  -moz-box-direction: reverse;
}
 
/* Safari、Opera 以及 Chrome */
.css {
  display: -webkit-box;
  -webkit-box-direction: reverse;
}
复制代码

四、box-pack 对盒子水平富裕空间的管理

/* start end center justify */
.css {
  -webkit-box-pack: center;
  -moz-box-pack: center;
  -ms-flex-pack: center;
  -o-box-pack: center;
  box-pack: center;
}
复制代码

五、box-pack 对盒子垂直方向富裕空间的管理

/* start end center */
/* box-align */
.css {
  -webkit-box-align: center;
  -moz-box-align: center;
  -ms-flex-align: center;
  -o-box-align: center;
  box-align: center;
}

复制代码

六、定义伸缩项目的具体位置

/*-moz-box-ordinal-group:1;*/    /* Firefox */
/*-webkit-box-ordinal-group:1;*/ /* Safari 和 Chrome */
 
.box div:nth-of-type(1){
  -webkit-box-ordinal-group:1;
}
 
.box div:nth-of-type(2){
  -webkit-box-ordinal-group:2;
}
 
.box div:nth-of-type(3){
  -webkit-box-ordinal-group:3;
}
 
.box div:nth-of-type(4){
  -webkit-box-ordinal-group:4;
}
 
.box div:nth-of-type(5){
  -webkit-box-ordinal-group:5;
}
复制代码

七、定义伸缩项目占空间的份数

/* -moz-box-flex: 2.0;     Firefox */
/* -webkit-box-flex: 2.0;  Safari 和 Chrome */

.css {
  .box div:nth-of-type(1){
    -webkit-box-flex:1;
  }
 
  .box div:nth-of-type(2){
    -webkit-box-flex:2;
  }
  
  .box div:nth-of-type(3){
    -webkit-box-flex:3;
  }
  
  .box div:nth-of-type(4){
    -webkit-box-flex:4;
  }
  
  .box div:nth-of-type(5){
    -webkit-box-flex:5;
  }
}

复制代码

移动web问题整理

欢迎留言 ~~

相关文章
相关标签/搜索