移动Web端资源整合
- meta篇
- viewreport 视窗宽度
View Code<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> width=device-width:是设置视窗宽度为设备视窗宽度,此宽度可以固定。 如:width = 640 则是640px的宽度(常见于微信); initial-scale= 1.0 :设置缩放比例为1.0; minimum-scale=1.0 和 maximum-scale=1.0 :最小缩放比例和最大缩放比例; user-scalable=no : 禁止用户自由缩放,默认值yes; 注:一般常用的,有 user-scalable=no 就不用使用 minimum-scale=1.0 和 maximum-scale=1.0 来强制禁止缩放了;
- 自动识别格式
View Code<meta name="format-detection" content="telephone=no"/> content:里面的参数telephone=no 是禁止浏览器自动识别手机号码,email=no 是禁止浏览器自动识别Email;
- 完整模版
View Code<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" /> <meta name="format-detection" content="telephone=no" /> <meta name="format-detection" content="email=no" />
- CSS篇
View Codebody { /*使用无衬线字体*/ font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif; /*禁止IOS调整字体大小*/ -webkit-text-size-adjust: 100% !important; } a, img { /*禁止长按链接与图片弹出菜单*/ -webkit-touch-callout: none; } html, body { /*禁止选中文本*/ -webkit-user-select: none; user-select: none; } button, input, optgroup, select, textarea { /*去掉webkit默认的表单样式*/ -webkit-appearance: none; appearance: none; } a, button, input, optgroup, select, textarea { /*去掉a、input和button点击时的蓝色外边框和灰色半透明背景*/ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } input::-webkit-input-placeholder { /*修改webkit中input的planceholder样式*/ color: #ccc } input:focus::-webkit-input-placeholder { /*修改webkit中focus状态下input的planceholder样式*/ color: #f00; } input::-webkit-input-speech-button { /*隐藏Android的语音输入按钮*/ display: none; }
- viewreport 视窗宽度
- Flex基础
-
假设flex容器为 .box ,子元素为 .item 。
View Code1.定义容器为flex布局 .box{ display: -webkit-flex; /*webkit*/ display: flex; } /*行内flex*/ .box{ display: -webkit-inline-flex; /*webkit*/ display:inline-flex; } 2.容器样式 .box{ flex-direction: row | row-reverse | column | column-reverse; /*主轴方向:左到右(默认) | 右到左 | 上到下 | 下到上*/ flex-wrap: nowrap | wrap | wrap-reverse; /*换行:不换行(默认) | 换行 | 换行并第一行在下方*/ flex-flow: <flex-direction> || <flex-wrap>; /*主轴方向和换行简写*/ justify-content: flex-start | flex-end | center | space-between | space-around; /*主轴对齐方式:左对齐(默认) | 右对齐 | 居中对齐 | 两端对齐 | 平均分布*/ align-items: flex-start | flex-end | center | baseline | stretch; /*交叉轴对齐方式:顶部对齐(默认) | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 文本基线对齐*/ align-content: flex-start | flex-end | center | space-between | space-around | stretch; /*多主轴对齐:顶部对齐(默认) | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 上下平均分布*/ } 3.子元素样式 .item{ order: <integer>; /*排序:数值越小,越排前,默认为0*/ flex-grow: <number>; /* default 0 */ /*放大:默认0(即如果有剩余空间也不放大,值为1则放大,2是1的双倍大小,以此类推)*/ flex-shrink: <number>; /* default 1 */ /*缩小:默认1(如果空间不足则会缩小,值为0不缩小)*/ flex-basis: <length> | auto; /* default auto */ /*固定大小:默认为0,可以设置px值,也可以设置百分比大小*/ flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] /*flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto,*/ align-self: auto | flex-start | flex-end | center | baseline | stretch; /*单独对齐方式:自动(默认) | 顶部对齐 | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 文本基线对齐*/ }
1.定义容器为flex布局 .box{ display: -webkit-flex; /*webkit*/ display: flex; } /*行内flex*/ .box{ display: -webkit-inline-flex; /*webkit*/ display:inline-flex; } 2.容器样式 .box{ flex-direction: row | row-reverse | column | column-reverse; /*主轴方向:左到右(默认) | 右到左 | 上到下 | 下到上*/ flex-wrap: nowrap | wrap | wrap-reverse; /*换行:不换行(默认) | 换行 | 换行并第一行在下方*/ flex-flow: <flex-direction> || <flex-wrap>; /*主轴方向和换行简写*/ justify-content: flex-start | flex-end | center | space-between | space-around; /*主轴对齐方式:左对齐(默认) | 右对齐 | 居中对齐 | 两端对齐 | 平均分布*/ align-items: flex-start | flex-end | center | baseline | stretch; /*交叉轴对齐方式:顶部对齐(默认) | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 文本基线对齐*/ align-content: flex-start | flex-end | center | space-between | space-around | stretch; /*多主轴对齐:顶部对齐(默认) | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 上下平均分布*/ } 3.子元素样式 .item{ order: <integer>; /*排序:数值越小,越排前,默认为0*/ flex-grow: <number>; /* default 0 */ /*放大:默认0(即如果有剩余空间也不放大,值为1则放大,2是1的双倍大小,以此类推)*/ flex-shrink: <number>; /* default 1 */ /*缩小:默认1(如果空间不足则会缩小,值为0不缩小)*/ flex-basis: <length> | auto; /* default auto */ /*固定大小:默认为0,可以设置px值,也可以设置百分比大小*/ flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] /*flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto,*/ align-self: auto | flex-start | flex-end | center | baseline | stretch; /*单独对齐方式:自动(默认) | 顶部对齐 | 底部对齐 | 居中对齐 | 上下对齐并铺满 | 文
-
- 小技巧篇
- 自定义苹果图标
View Code在网站文件根目录放一个 apple-touch-icon.png 文件,苹果设备保存网站为书签或桌面快捷方式时,就会使用这个文件作为图标,文件尺寸建议为:180px × 180px。
- 自定义favicon
View Code<link rel="icon" href="favicon.ico" mce_href="favicon.ico" type="image/x-icon">
- 定义浏览器点击行为
View Code<a href="tel:080-10086">打电话给:080-10086</a> <a href="sms:10000">发短信给: 10000</a> <a href="mailto:me@22278.club">发送邮件: me@22278.club</a>
- 定义上传文件类型和格式
View Code<input type=file accept="image/*"> accept:可以限制上传文件的类型,参数为image/*是所有图片类型,点击会弹出图库,也可以指定图片格式,参数设置成image/png则可以限制图片类型为png; 参数如果为video/*则是选择视频的意思; accept:可以设置多个文件格式,语法为:accept="image/gif, image/jpeg" ;
- 使用box-shadow改变(挡住)表单自动填充后的黄色
View Codeinput:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill{ box-shadow:inset 0 0 0 1000px #fff; } - 用CSS实现省略号文字截断
View Codewhite-space: nowrap; text-overflow: ellipsis; - 使用border绘制小三角
View Code原理是:上下和左右的边框对接其实是个斜角,利用这个特性,使其中一边的边框透明,另外一边写成想要的颜色并隐藏对边,就可以变成小箭头形状。 border-width: 10px 10px 10px 0; //左箭头 border-color: transparent #fff; border-style: solid; width: 0; tootip写法: <!--html--> <div class="box">嗨!点击菜单就可以关注兮兮公众号了哟~</div> /*--css--*/ .box{ position: relative; padding: 0 20px; width: 380px; height: 80px; border-radius: 8px; background: #efefef; font-size: 18px; line-height: 80px; } .box:after{ position: absolute; top: 50%; left: -15px; z-index: 1; display: block; margin-top: -15px; width: 0; border-color: transparent #efefef; border-style: solid; border-width: 15px 15px 15px 0; content: ""; }
- 自定义苹果图标

浙公网安备 33010602011771号