01-05 移动端适配rem方案
适配方案 – rem+动态html的font-size
rem的font-size尺寸
方式一:动态font-size-媒体查询
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> @media screen and (min-width: 320px) { html { font-size: 20px; } } @media screen and (min-width: 375px) { html { font-size: 24px; } } @media screen and (min-width: 414px) { html { font-size: 28px; } } @media screen and (min-width: 480px) { html { font-size: 32px; } } .box { width: 5rem; height: 5rem; background-color: orange; } </style> </head> <body> <div class="box"> </div> </body> </html>
方式二:动态font-size-JS动态计算
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./js/hy_flexible.js"></script> <style> body { font-size: 16px; } .box { width: 5rem; height: 5rem; background-color: orange; } p { font-size: 0.5rem; } </style> </head> <body> <div class="box"> </div> <p>我是文本</p> <!-- 动态的修改html的font-size --> <span>哈哈哈哈哈哈</span> </body> </html>
方式三:动态font-size-lib-flexible
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./js/lib_flexible.js"></script> <style> .box { width: 5rem; height: 5rem; background-color: orange; } p { font-size: 0.5rem; } </style> </head> <body> <div class="box"> </div> <p>我是文本</p> </body> </html>
rem的单位换算
插件的设置:扩展设置
06-07 移动端适配vw方案
考拉海购设计稿
适配方案 - vw
vw和rem的对
vw的单位换算
vw的单位换算
08_(掌握)grid布局-介绍-概念-常见属性
认识grid布局
grid布局重要的概念
grid布局常见属性
09_(掌握)考拉海购-index搭建和head配置
做这个:
10_(掌握)考拉海购-reset重置和目录结构
目前,先做静态页面,JS后再做动态页面。
11_(掌握)考拉海购-项目tabbar的搭建过程
先做:
12_(掌握)考拉海购-download布局和vw转换
13_(掌握)考拉海购-download细节布局处理
渐变背景色:
@import url(./variables.less);
@import url(./mixins.less);
.download {
display: flex;
height: 16vw;
box-sizing: border-box;
border-bottom: 1px solid #e3e3e3;
background-color: #fff;
.left {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
overflow: hidden;
padding: 0 3.2vw;
.logo {
width: 10.6667vw;
height: 10.6667vw;
border-radius: 2.13333vw;
box-shadow: 0 0 0.93333vw 0 rgba(0,0,0,.15);
}
.info {
flex: 1;
overflow: hidden;
margin-left: 2.1333vw;
.title {
color: #333;
font-size: @normalFontSize;
.nowrap();
}
.desc {
margin-top: .5333vw;
color: #999;
font-size: @smallFontSize;
.nowrap();
}
}
}
.right {
width: 25.2vw;
text-align: center;
height: 16vw;
line-height: 16vw;
color: #fff;
font-size: @bigFontSize;
background-image: linear-gradient(to right, #ff0409,#ff3162);
}
}
14_(掌握)考拉海购-subsidy的header展示
做补贴
@import url(./variables.less);
.subsidy {
width: 93.6vw;
height: 44vw;
margin: 3.2vw auto 0;
box-sizing: border-box;
padding: 0 2.6667vw;
background-color: #fff;
border-radius: 3.2vw;
.header {
display: flex;
justify-content: space-between;
align-items: center;
height: 10.6667vw;
.left {
display: flex;
align-items: flex-end;
img {
width: 16.8vw;
}
.time {
display: flex;
margin-left: 1.3333vw;
align-items: center;
font-size: @smallFontSize;
.item {
width: 5.3333vw;
height: 4.2667vw;
text-align: center;
line-height: 4.2667vw;
color: #fff;
background-color: @mainColor;
border-radius: .8vw;
}
.split {
color: @mainColor;
margin: 0 .8vw;
}
}
}
.right {
position: relative;
padding-right: 8px;
font-size: @smallFontSize;
color: @mainColor;
&::after {
content: "";
position: absolute;
width: 1.2vw;
height: 1.2vw;
top: 0;
bottom: 0;
margin: auto 0;
border: .2667vw solid @mainColor;
border-top-color: transparent;
border-left-color: transparent;
transform: rotate(-45deg);
}
}
}
.list {
display: flex;
.item {
flex: 1;
text-align: center;
img {
width: 20.9333vw;
}
.info {
font-size: @smallFontSize;
.new {
display: flex;
align-items: center;
color: @mainColor;
.unit {
font-weight: 700;
}
.money {
font-size: 4vw;
font-weight: 700;
}
}
.old {
color: #777;
text-decoration: line-through;
}
}
}
}
}
15_(掌握)考拉海购-subsidy的list展示
16_(掌握)考拉海购-category类别的展示
@import url(./variables.less);
.category {
display: flex;
margin: 5.3333vw 0 2.6667vw;
padding: 0 3.2vw;
.item {
flex: 1;
text-align: center;
.title {
font-size: @bigFontSize;
color: #666;
}
.subtitle {
height: 4.2667vw;
padding: 0 1.6vw;
font-size: @smallFontSize;
border-radius: 2.4vw;
color: #999;
}
&.active {
.title {
color: @mainColor;
}
.subtitle {
color: #fff;
background-color: @mainColor;
}
}
}
}
17_(掌握)考拉海购-Product整体布局展示
18_(掌握)考拉海购-Product中item内容展示
@import url(./variables.less);
body {
font-size: @normalFontSize;
background-color: #f5f5f5;
}
// tags tag
.tags {
display: flex;
flex-wrap: wrap;
}
.tags .tag {
height: 3.2vw;
line-height: 3.2vw;
position: relative;
margin-right: .8vw;
margin-top: .5333vw;
padding: 0 .8vw;
font-size: 3.2vw;
color: @mainColor;
border: 1px solid @mainColor;
border-radius: .8vw;
&.ticket {
padding-left: 27px;
}
&.ticket::before {
content: "券";
position: absolute;
top: 0;
bottom: 0;
left: 0;
padding: 0 1.6vw;
background-color: @lightBgColor;
}
}
总结
一. 移动端适配方案
1.1. 整理常见方案
-
百分比
-
不推荐
-
不同位置的百分比相对参照物不一样
-
-
rem + 动态的html的font-size
-
vw
-
flex
1.2. rem+动态的font-size
1.2.1. 动态的font-size
-
方案一: 媒体查询
-
方案二: 手写js设置html的font-size
-
方案三: lib-flexible
1.2.2. px转rem单位
-
方案一: 手动(计算器)
-
方案二: less混入
-
方案三: webpack插件(后续)
-
方案四: vscode插件
-
设置 font-size
-
1.3. vw
1.3.1. 回顾vw
-
rem和vw联系在一起
-
1rem = 10vw
1.3.2. px转vw单位
-
方案一: 手动(计算器)
-
方案二: less混入
-
方案三: webpack插件(后续)
-
方案四: vscode插件
-
设置设计稿的大小
-
二. grid布局
2.1. grid介绍/重要概念
2.2. grid布局中的属性
-
学习地址
三. 考拉海购
3.1. tabbar模块
3.2. download模块
3.3. subsidy模块
3.4. category模块
3.5. product
-
product整体布局
-
item内容布局
-
tags/tag封装
练习
一. 完成上课所有的代码
二. 完成考拉的其他模块
三. 做项目
-
分享