文章目录
- 移动端
-
- 一、移动终端基础
-
- **1 .浏览器现状**
- **2 .手机屏幕现状**
- **3.移动终端常见的屏幕尺寸**
- **4.移动调试方法**
- 5.总结
- 二、视口
-
- **1.布局视口** `layout viewport`
- **2.视觉视口**`visual viewport`
- **3.理想视口** `ideal viewport`
- 4.meta视口标签
- 三、二倍图
-
- **1.物理像素&物理像素比**
- 2.**多倍图**
- 3.**背景缩放 background-size**
- **4.多倍图切图 cutterman**
- 四、移动开发选择
-
- 1.单独制作移动终端页面(主流)
- 2.与移动终端(其次)兼容的响应页面
- 五、移动终端技术解决方案
-
- **1 移动浏览器**
- **2.`CSS`初始化** `**normalize.css`**
- 3 CSS3 盒子模型box-sizing
- **4.特殊样式**
- 六、移动终端常见布局
-
-
- 1. 单独制作移动终端页面(主流)
- 2.与移动终端(其次)兼容的响应页面
-
- 七、移动终端开发流式布局
- 八、京东移动终端首页制作
-
- **1.技术选型**
- **2. 构建相关文件夹结构**
- **4. 常用初始化样式**
- 九、**移动WEB开发之flex布局**
-
- 1.flex布局体验
-
- **1.1 传统布局与flex布局**
- **1.2 初体验**
- **2. flex布局原理**
-
- **1 布局原理**
- **3.常见的父项属性**
-
-
- 1).flex-direction 属性决定了主轴的方向(即项目的排列方向)
- 2)justify-content 设置主轴上的子元素排列方法
- 3)**flex-wrap** **设置子元素是否换行**
- 4)align-items 设置侧轴上的子元素排列方式(单行 )
- 5)**align-content** 侧轴上子元素的布置(多行)
- 6)flex-flow
-
- 4.flex布局子项的常见属性
-
-
- 1).flex
- 2).**align-self** **控制子项在侧轴上的排列**
- 3). **order** 属性定义项目的排列顺序
-
- 十、携程首页案例制作
-
-
- **1. 技术选型**
- **2. 构建相关文件夹结构**
- **3. 设置视觉标签,引入初始样式**
- 四、常用的初始化风格
- 5. **常见模块命名**
- 6.**常见flex布局思路**
-
- 背景线性渐变
- 十二、**移动WEB开发之rem适配布局**
-
- 1.rem 基础
- 2.媒体查询
-
- **1)什么是媒体查询?**
- 2)语法规范
-
-
- **mediatype 查询类型**
- **关键字**
- **媒体特性**
-
- 3)案例
-
-
- **媒体查询修改背景颜色**
-
- **4)媒体查询 rem实现元素变化**
- 5) **引入资源(理解)**
- 3.less
-
- **1)维护 css 的弊端**
- **2)Less 介绍**
- **3)Less 安装(使用时注意vscode无需安装less)**
- 4)Less使用
- 5) Less 变量
- 6)Less编译
- 7)Less嵌套
- 8)Less运算
- 9)Less详细学习
- 4.rem适配方案
-
- **1)我们适应的目标是什么?**
- 2)**如何实现这个目标?**
- **3)用于实际开发**
- **4)rem 使用适应方案技术(市场主流)**
-
-
- **技术方案1**
- **技术方案2(推荐)**
-
- 5) rem 媒体查询 less 技术
-
- (1)设计稿的常见尺寸和宽度
- (2)动态设置 html 标签 font-size 大小
- **(3)元素大小取值方法**
- 6)flexible.js rem技术
- 十三、苏宁网页案例制作
-
-
- (一)rem + 媒体查询 + less 技术制作苏宁移动端首页
-
- **1. 技术选型**
- **2. 搭建相关文件夹结构**
- **3. 设置视口标签以及引入初始化样式**
- **4. 设置公共common.less文件**
- 5. 新建index.less文件
- **6. body样式**
- (二)flexible.js+rem技术
-
- **1. 技术选型**
- **2. 搭建相关文件夹结构**
- 3. 设置视口标签以及引入初始化样式还有js文件
- 4. body样式
-
- 十四、VSCode px 转换rem 插件cssrem
- 十五、黑马面面布局开发
-
- 1.目的
-
- 1.1 技术方案
- 1.2 代码规范
- 1.2 目录规范
- 2.流程开发
-
- 2.1 蓝湖/摹客协作平台
- 2.2 适配方案
- 2.3 初始化文件
- 2.4 布局模块
- 2.5 swiper 插件使用
- 2.6 上传码云并发布部署静态网站
- 十六、**移动端WEB开发之响应式布局**
-
- **1. 响应式开发**
-
- **1.1 响应式开发原理**
- **1.2 响应式布局容器**
- **1.3 响应式导航**
- **2.Bootstrap前端开发框架**
-
- **2.1 Bootstrap 简介**
- **2.2 Bootstrap 使用**
- **2.3 布局容器**
- **3. Bootstrap 栅格系统**
-
- **3.1 栅格系统简介**
- **3.2 栅格选项参数**
- **3.3 列嵌套**
- **3.4 列偏移**
- **3.5 列排序**
- **3.6 响应式工具**
- 3.7 其他
- 十七、阿里百秀首页案例
-
-
-
- **技术选型**
- **需求分析**
-
- **1.页面布局分析**
- **2. 屏幕划分分析**
- **页面制作**
-
-
- 十八、vw/vh移动端布局
-
- 1.移动端布局
- 2.vw/vh是什么
- 3.vw/vh怎么用
- 4.vw 注意事项
- 十九、案例实战-bibi官网首页头部
-
-
-
- bibi官网移动端首页布局
-
-
- 二十、移动端布局总结
-
-
- **移动端主流方案**
-
-
- 1.单独制作移动端页面(主流)
- 2.响应式页面兼容移动端(其次)
-
- **移动端技术选型**
-
移动端
一、移动端基础
国内的UC和QQ,百度等手机浏览器都是根据修改过来的内核,国内尚无自主研发的内核,就像国内的手机操作系统都是基于Android修改开发的一样。
总结:主流浏览器,处理内核浏览器即可。
-
移动端设备屏幕尺寸非常多,碎片化严重。
-
Android设备有多种分辨率:480x800, 480x854, 540x960, 720x1280,1080x1920等,还有传说中的2K,4k屏。
-
近年来iPhone的碎片化也加剧了,其设备的主要分辨率有:640x960, 640x1136, 750x1334, 1242x2208等。
-
作为开发者无需关注这些分辨率,因为我们常用的尺寸单位是
px
。
注:作为前端开发,不建议大家去纠结dp,dpi,pt,ppi
等单位。
-
Chrome DevTools
(谷歌浏览器)的模拟手机调试 -
搭建本地web服务器,手机和服务器一个局域网内,通过手机访问服务器
-
使用外网服务器,直接IP或域名访问
5.总结
-
移动端浏览器我们主要对
webkit
内核进行兼容 -
我们现在开发的移动端主要针对手机端开发
-
现在移动端碎片化比较严重,分辨率和屏幕尺寸大小不一
-
学会用谷歌浏览器模拟手机界面以及调试
二、视口
1.布局视口 layout viewport
-
一般移动设备的浏览器都默认设置了一个布局视口,用于解决早期的PC端页面在手机上显示的问题。
-
iOS, Android基本都将这个视口分辨率设置为 980px,所以PC上的网页大多都能在手机上呈现,只不过元素看上去很小,一般默认可以通过手动缩放网页。
2.视觉视口 visual viewport
-
字面意思,它是用户正在看到的网站的区域。
注意:是网站的区域。 -
我们可以通过缩放去操作视觉视口,但不会影响布局视口,布局视口仍保持原来的宽度。
3.理想视口 ideal viewport
-
为了使网站在移动端有最理想的浏览和阅读宽度而设定
-
理想视口,对设备来讲,是最理想的视口尺寸
-
需要手动添写meta视口标签通知浏览器操作
-
meta视口标签 的主要目的:布局视口的宽度应该与理想视口的宽度一致,简单理解就是设备有多宽,我们布局的视口就多宽
4.meta视口标签
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<!-- 标准的viewport设置 视口宽度和设备保持一致 视口的默认缩放比例1.0 不允许用户自行缩放 最大允许的缩放比例1.0 最小允许的缩放比例1.0 -->
属性 | 解释说明 |
---|---|
width | 宽度设置的是viewport宽度,可以设置device-width特殊值 |
initial-scale | 初始缩放比,大于0的数字 |
maximum-scale | 最大缩放比,大于0的数字 |
minimum-scale | 最小缩放比,大于0的数字 |
user-scalable | 用户是否可以缩放,yes或no(1或0) |
三、二倍图
1.物理像素&物理像素比
-
物理像素点指的是屏幕显示的最小颗粒,是物理真实存在的。这是厂商在出厂时就设置好了,比如苹果6\7\8 是 750* 1334
-
我们开发时候的1px 不是一定等于1个物理像素的
-
PC端页面,1个px 等于1个物理像素的,但是移动端就不尽相同
-
一个px的能显示的物理像素点的个数,称为物理像素比或屏幕像素比
-
PC端 和 早前的手机屏幕 / 普通手机屏幕: 1CSS像素 = 1 物理像素的
-
Retina(视网膜屏幕)是一种显示技术,可以将把更多的物理像素点压缩至一块屏幕里,从而达到更高的分辨率,并提高屏幕显示的细腻程度。
2.多倍图
-
对于一张 50px * 50px 的图片,在手机 Retina 屏中打开,按照刚才的物理像素比会放大倍数,这样会造成图片模糊
-
在标准的viewport设置中,使用倍图来提高图片质量,解决在高清设备中的模糊问题
-
通常使用二倍图, 因为iPhone 6\7\8 的影响,但是现在还存在3倍图4倍图的情况,这个看实际开发公司需求
-
背景图片 注意缩放问题
/* 在 iphone8 下面 */
img{
/*原始图片100*100px*/
width: 50px;
height: 50px;
}
.box{
/*原始图片100*100px*/
background-size: 50px 50px;
}
3.背景缩放 background-size
background-size 属性规定背景图像的尺寸
background-size: 背景图片宽度 背景图片高度;
-
单位: 长度|百分比|cover|contain;
-
cover把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。
-
contain把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域
4.多倍图切图 cutterman
四、移动端开发选择
1.单独制作移动端页面(主流)
- 通常情况下,网址域名前面加
m(mobile) 可以打开移动端。通过判断设备,如果是移动设备打开,则跳到移动端页面 。 - 京东商城手机版
- 淘宝触屏版
- 苏宁易购手机版
2.响应式页面兼容移动端(其次)
- 三星手机官网:通过判断屏幕宽度来改变样式,以适应不同终端。
- **缺点:**制作麻烦, 需要花很大精力去调兼容性问题
五、移动端技术解决方案
1 移动端浏览器
-
移动端浏览器基本以 webkit 内核为主,因此我们就考虑webkit兼容性问题。
-
我们可以放心使用
H5
标签和CSS3
样式。 -
同时我们浏览器的私有前缀我们只需要考虑添加 webkit 即可
2.CSS
初始化 **normalize.css
**
CSS
初始化移动端 CSS
初始化推荐使用 normalize.css/
-
Normalize.css
:保护了有价值的默认值 -
Normalize.css
:修复了浏览器的bug -
Normalize.css
:是模块化的 -
Normalize.css
:拥有详细的文档
官网地址: http://necolas.github.io/normalize.css/
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document ========================================================================== */
/** * 1. Correct the line height in all browsers.修正所有浏览器中的行高 * 2. Prevent adjustments of font size after orientation changes in iOS.防止在iOS中改变方向后调整字体大小。 */
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections ========================================================================== */
/** * Remove the margin in all browsers.在所有浏览器中删除边距。 */
body {
margin: 0;
}
/** * Render the `main` element consistently in IE.在IE中始终渲染“主”元素。 */
main {
display: block;
}
/** * Correct the font size and margin on `h1` elements within `section` and `article` contexts in Chrome, Firefox, and Safari. 在Chrome, Firefox和Safari中,在“section”和“article”上下文中的“h1”元素的字体大小和空白 */
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content ========================================================================== */
/** * 1. Add the correct box sizing in Firefox. 1. 在Firefox中添加正确的框大小。 * 2. Show the overflow in Edge and IE. 2. 在Edge和IE中显示溢出。 */
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/** * 1. Correct the inheritance and scaling of font size in all browsers.修正所有浏览器中字体大小的继承和缩放。 * 2. Correct the odd `em` font sizing in all browsers. 纠正所有浏览器中奇怪的' em '字体大小。 */
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics ========================================================================== */
/** * Remove the gray background on active links in IE 10.移除IE 10中活动链接的灰色背景。 */
a {
background-color: transparent;
}
/** * 1. Remove the bottom border in Chrome 57- 删除底部边界在Chrome浏览器 * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.在Chrome、Edge、IE、Opera和Safari中添加正确的文本装饰 */
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/** * Add the correct font weight in Chrome, Edge, and Safari.在Chrome、Edge和Safari中添加正确的字体粗细 */
b, label {
font-weight: bolder;
}
/** * 1. Correct the inheritance and scaling of font size in all browsers.修正所有浏览器中字体大小的继承和缩放。 * 2. Correct the odd `em` font sizing in all browsers.纠正所有浏览器中奇怪的' em '字体大小 */
code, kbd, samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/** * Add the correct font size in all browsers.在所有浏览器中添加正确的字体大小。 */
small {
font-size: 80%;
}
/** * Prevent `sub` and `sup` elements from affecting the line height in all browsers. *防止' sub '和' sup '元素影响所有浏览器中的行高。 */
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content ========================================================================== */
/** * Remove the border on images inside links in IE 10.在IE 10中删除链接内图像的边框。 */
img {
border-style: none;
}
/* Forms ========================================================================== */
/** * 1. Change the font styles in all browsers. 更改所有浏览器中的字体样式。 * 2. Remove the margin in Firefox and Safari. 删除Firefox和Safari中的空白。 */
button, input, optgroup, select, textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/** * Show the overflow in IE. IE显示溢出。 * 1. Show the overflow in Edge.在边缘显示溢出。 */
button, input {
/* 1 */
overflow: visible;
}
/** * Remove the inheritance of text transform in Edge, Firefox, and IE.在Edge、Firefox和IE中移除文本转换的继承。 * 1. Remove the inheritance of text transform in Firefox.在Firefox中删除文本转换的继承。 */
button, select {
/* 1 */
text-transform: none;
}
/** * Correct the inability to style clickable types in iOS and Safari.修正了在iOS和Safari中无法样式化可点击类型的问题。 */
button, [type="button"], [type="reset"], [type="submit"] {
-webkit-appearance: button;
}
/** * Remove the inner border and padding in Firefox.删除Firefox中的内边框和填充。 */
button::-moz-focus-inner, [type="button"]::-moz-focus-inner, [type="reset"]::-moz-focus-inner, [type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/** * Restore the focus styles unset by the previous rule.恢复先前规则未设置的焦点样式。 */
button:-moz-focusring, [type="button"]:-moz-focusring, [type="reset"]:-moz-focusring, [type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/** * Correct the padding in Firefox. */
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/** * 1. Correct the text wrapping in Edge and IE.修正边缘和IE中的文本包装。 * 2. Correct the color inheritance from `fieldset` elements in IE.修正了IE中' fieldset '元素的颜色继承。 * 3. Remove the padding so developers are not caught out when they zero out`fieldset` elements in all browsers. 去掉填充,这样当开发者在所有浏览器中归零“fieldset”元素时就不会被发现。 */
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/** * Add the correct vertical alignment in Chrome, Firefox, and Opera.在Chrome、Firefox和Opera中添加正确的垂直对齐 */
progress {
vertical-align: baseline;
}
/** * Remove the default vertical scrollbar in IE 10+.:删除IE 10+中默认的垂直滚动条。 */
textarea {
overflow: auto;
}
/** * 1. Add the correct box sizing in IE 10.1. 在IE 10中添加正确的框大小。 * 2. Remove the padding in IE 10.2. 移除IE 10中的填充。 */
[type="checkbox"], [type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/** * Correct the cursor style of increment and decrement buttons in Chrome.修正了Chrome中递增和递减按钮的光标样式。 */
[type="number"]::-webkit-inner-spin-button, [type="number"]::-webkit-outer-spin-button {
height: auto;
}
/** * 1. Correct the odd appearance in Chrome and Safari.修正Chrome和Safari中奇怪的外观。 * 2. Correct the outline style in Safari.修正Safari中的轮廓样式 */
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/** * Remove the inner padding in Chrome and Safari on macOS.在macOS上移除Chrome和Safari的内填充。 */
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/** * 1. Correct the inability to style clickable types in iOS and Safari.修正了在iOS和Safari中无法样式化可点击类型的问题。 * 2. Change font properties to `inherit` in Safari.在Safari中更改字体属性为“inherit”。 */
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive ========================================================================== */
/* * Add the correct display in Edge, IE 10+, and Firefox.在Edge、IE 10+和Firefox中添加正确的显示。 */
details {
display: block;
}
/* * Add the correct display in all browsers.在所有浏览器中添加正确的显示。 */
summary {
display: list-item;
}
/* Misc ========================================================================== */
/** * Add the correct display in IE 10+.在ie10 +中添加正确的显示。 */
template {
display: none;
}
/** * Add the correct display in IE 10.在ie10中添加正确的显示。 */
[hidden] {
display: none;
}
3 CSS3 盒子模型box-sizing
-
传统模式宽度计算:盒子的宽度 = CSS中设置的width + border + padding
-
`CSS3盒子模型: 盒子的宽度 = CSS中设置的宽度width 里面包含了 border 和 padding
也就是说,我们的CSS3中的盒子模型, padding 和 border 不会撑大盒子了
4.特殊样式
/*CSS3盒子模型*/
box-sizing: border-box;
-webkit-box-sizing: border-box;
/*点击高亮我们需要清除清除 设置为transparent 完成透明*/
-webkit-tap-highlight-color: transparent;
/*在移动端浏览器默认的外观在iOS上加上这个属性才能给按钮和输入框自定义样式*/
-webkit-appearance: none;
/*禁用长按页面时的弹出菜单*//*ios上独有*/
img,a {
-webkit-touch-callout: none; }
六、移动端常见布局
1. 单独制作移动端页面(主流)
-
流式布局(百分比布局)
-
flex 弹性布局(强烈推荐)
-
less+rem+媒体查询布局
-
混合布局
2.响应式页面兼容移动端(其次)
- 媒体查询
bootstarp
七、移动端开发之流式布局
-
流式布局,就是百分比布局,也称非固定像素布局。
-
通过盒子的宽度设置成百分比来根据屏幕的宽度来进行伸缩,不受固定像素的限制,内容向两侧填充。
-
流式布局方式是移动web开发使用的比较常见的布局方式
-
max-width 最大宽度 (max-height 最大高度)
-
min-width 最小宽度 (min-height 最小高度)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style> * {
margin: 0; padding: 0; } section {
width: 100%; max-width: 980px; min-width: 320px; margin: 0 auto; } section div {
/* float: left; */ width: 50%; height: 400px; } section div:nth-child(1) {
background-color: pink; } section div:nth-child(2) {
background-color: purple; } </style>
</head>
<body>
<section>
<div></div>
<div></div>
</section>
</body>
</html>
八、京东移动端首页制作
1.技术选型
-
方案:我们采取单独制作移动页面方案
-
技术:布局采取流式布局
2. 搭建相关文件夹结构
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/index.css">
4. 常用初始化样式
body {
margin: 0 auto;
min-width: 320px;
max-width: 640px;
background: #fff;
font-size: 14px;
font-family: -apple-system, Helvetica, sans-serif;
line-height: 1.5;
color: #666;
}
/*点击高亮我们需要清除清除 设置为transparent 完成透明*/
* {
-webkit-tap-highlight-color: transparent;
}
/*在移动端浏览器默认的外观在iOS上加上这个属性才能给按钮和输入框自定义样式*/
input {
-webkit-appearance: none;
}
/*禁用长按页面时的弹出菜单*/
img, a {
-webkit-touch-callout: none;
}
a {
color: #666;
text-decoration: none;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
img {
vertical-align: middle;
}
div {
/* css3 盒子模型 */
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.clearfix:after {
content: "";
display: block;
line-height: 0;
visibility: hidden;
height: 0;
clear: both;
}
项目下载
九、移动WEB开发之flex布局
1.flex布局体验
1.1 传统布局与flex布局
-
兼容性好
-
布局繁琐
-
局限性,不能再移动端很好的布局
-
操作方便,布局极为简单,移动端应用很广泛
-
PC 端浏览器支持情况较差
-
IE 11或更低版本,不支持或仅部分支持
-
如果是PC端页面布局,我们还是传统布局。
-
如果是移动端或者不考虑兼容性问题的PC端页面布局,我们还是使用flex弹性布局
1.2 初体验
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta 标签:
sub板端连接器