目的
了解移动端页面开发流程
掌握移动端常见布局思路
技术方案
弹性盒子 + rem + LESS
最小适配设备为iphone5 320px
最大设配设备为iphone8plus
(ipad能正常查看内容即可)
代码规范
类名语义化,尽量精短、明确,必须以字母开头命名,且全部字母为小写,单词之间统一使用下划线“_” 连接
类名嵌套层次尽量不超过三层
尽量避免直接使用元素选择器
属性书写顺序 布局定位属性:display
/ position
/ float
/ clear
/ visibility
/ overflow
尺寸属性:width
/ height
/ margin
/ padding
/ border
/ background
文本属性:color
/ font
/ text-decoration
/ text-align
/ vertical-align
其他属性(CSS3):content
/ cursor
/ border-radius
/ box-shadow
/ text-shadow
避免使用id选择器
避免使用通配符*
和!important
目录规范 项目文件夹:heimamm
样式文件夹:css
业务类图片文件夹:images
样式类图片文件夹: icons
流程开发 蓝湖/摹客协作平台
UI设计师 psd效果图完成后,会上传到蓝湖//摹客里面,同时会拉前端工程师进入开发
大部分情况下,UI会把图片按照前端设计要求给切好
UI设计师 上传蓝湖到或者/摹客
1.摹客官网地址: https://www.mockplus.cn/
注册一个账号 2.下载moke ps
插件 3.PS 安装/摹客/蓝湖插件 3.打开PS/摹客/蓝湖插件 4.上传(需要切图,需要先标注切图) 5.查看项目 6.邀请成员进入(分享按钮,链接地址)
适配方案
flex 布局
百分比布局
rem布局
vw/vh布局
响应式布局
本次案例 flex + rem + + flexible.js + LESS
初始化文件
引入normalize.css
less
中初始化body
样式
约束范围
1 2 3 4 5 @media screen and (min-width: 750px ) { html { font-size : 37.5px !important ; } }
布局模块
头部模块 .header
高度为 80px
nav
模块制作多用flex
充电学习 阴影1 box-shadow : 0 0px 10px rgba (0, 0, 0, 0.1 )
前期准备 HTML代码
1 2 3 4 <link rel ="stylesheet" href ="./css/normalize.css" /> <link rel ="stylesheet" href ="./css/swiper.min.css" /> <link rel ="stylesheet" href ="./css/index.css" />
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 body { min-width : 320px ; max-width : 750px ; margin : 0 auto; background-color : #f2f4f7 ; }a { text-decoration : none; color : #707070 ; }@media screen and (min-width : 750px ) { html { font-size : 37.5px !important ; } }
头部区域 HTML代码
1 2 3 4 5 <section class ="warp" > <header class ="header" > 面面俱到</header > </section >
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 .warp { background-color : #fff ; padding-bottom : 1.146667rem ; }.header { height : 2.133333rem ; border-bottom : .026667rem solid #eaeaea ; text-align : center; line-height : 2.133333rem ; font-size : 0.933333rem ; color : #1c1c1c ; }
导航栏区域 HTML代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <nav class ="nav" > <a href ="#" class ="item" > <img src ="./icons/icon1.png" alt ="" /> <span > HR面试</span > </a > <a href ="#" class ="item" > <img src ="./icons/icon2.png" alt ="" /> <span > 笔试</span > </a > <a href ="#" class ="item" > <img src ="./icons/icon3.png" alt ="" /> <span > 技术面试</span > </a > <a href ="#" class ="item" > <img src ="./icons/icon4.png" alt ="" /> <span > 模拟面试</span > </a > <a href ="#" class ="item" > <img src ="./icons/icon5.png" alt ="" /> <span > 面试技巧</span > </a > <a href ="#" class ="item" > <img src ="./icons/icon6.png" alt ="" /> <span > 薪资查询</span > </a > </nav >
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 .nav { display : flex; flex-wrap : wrap; padding : 1.2rem 0 1.6rem 0 ; .item { display : flex; width : 33.33% ; flex-direction : column; align-items : center; img { width : 3.706667rem ; height : 3.706667rem ; } span { font-size : 0.666667rem ; color : #707070 ; } & :nth-child(-n + 3 ) { margin-bottom : 1.653333rem ; } } }
go模块 HTML代码
1 2 3 4 <section class ="go" > <img src ="./images/go.png" alt ="" /> </section >
LESS代码
1 2 3 .go { margin : 0 0.266667rem 0 0.48rem ; }
就业指导模块 HTML代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 <section class ="content" > <div class ="con-hd" > <h4 > <span class ="icon" > <img src ="./icons/i2.png" alt ="" /> </span > 就业指导 </h4 > <a href ="#" class ="more" > 更多>></a > </div > <div class ="get_job_focus" > <div class ="swiper-container get_job_fo" > <div class ="swiper-wrapper" > <div class ="swiper-slide" > <a href ="#" > <img src ="./images/pic.png" alt ="" /> </a > <p > 老师教你应对面试技巧</p > </div > <div class ="swiper-slide" > <a href ="#" > <img src ="./images/ldh.jpg" alt ="" /> </a > <p > 老师教你应对面试技巧</p > </div > <div class ="swiper-slide" > <a href ="#" > <img src ="./images/3.jpg" alt ="" /> </a > <p > 老师教你应对面试技巧</p > </div > </div > </div > <div class ="swiper-button-next" > </div > <div class ="swiper-button-prev" > </div > </div > </section >
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 .content { padding : 1.066667rem 0.64rem ; background-color : #fff ; margin-top : 0.266667rem ; .con-hd { display : flex; justify-content : space-between; height : 1.013333rem ; line-height : 1.013333rem ; margin-bottom : 0.906667rem ; h4 { margin : 0 ; font-size : 0.746667rem ; color : #333333 ; .icon { display : inline-block; width : 1.013333rem ; height : 1.013333rem ; vertical-align : middle; } } .more { font-size : 0.586667rem ; color : #999999 ; } } }.get_job_focus { position : relative; .swiper-container { height : 100% ; width : 14.4rem ; } .swiper-slide { text-align : center; font-size : 18px ; background : #fff ; display : -webkit-box; display : -ms-flexbox; display : -webkit-flex; display : flex; flex-direction : column; display : -webkit-box; display : -ms-flexbox; display : -webkit-flex; display : flex; -webkit-box-pack : center; -ms-flex-pack : center; -webkit-justify-content : center; justify-content : center; -webkit-box-align : center; -ms-flex-align : center; -webkit-align-items : center; align-items : center; transition : 300ms ; transform : scale(0.8 ); opacity : 0.4 ; a { width : 9.013333rem ; height : 10.026667rem ; img { width : 100% ; height : 100% ; } } p { width : 9.013333rem ; font-size : 0.666667rem ; margin-top : 0.64rem ; color : #333 ; } } .swiper-slide-active , .swiper-slide-duplicate-active { transform : scale(1 ); z-index : 999 ; opacity : 1 ; } .swiper-button-next , .swiper-button-prev { outline : none; & :after { font-size : 1.066667rem ; color : #333 ; } } }
充电学习模块 HTML代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 <section class ="content study_con" > <div class ="con-hd" > <h4 > <span class ="icon" > <img src ="./icons/i2.png" alt ="" /> </span > 充电学习 </h4 > <a href ="#" class ="more" > 更多>></a > </div > <div class ="study" > <div class ="swiper-container study_fo" > <div class ="swiper-wrapper" > <div class ="swiper-slide" > <img src ="./images/pic1.png" alt ="" /> <h5 > 说低调英语,告别中式英语</h5 > <p > 156人学习</p > </div > <div class ="swiper-slide" > <img src ="./images/pic2.png" alt ="" /> <h5 > 说低调英语,告别中式英语</h5 > <p > 156人学习</p > </div > <div class ="swiper-slide" > <img src ="./images/pic1.png" alt ="" /> <h5 > 说低调英语,告别中式英语</h5 > <p > 156人学习</p > </div > <div class ="swiper-slide" > <img src ="./images/pic1.png" alt ="" /> <h5 > 说低调英语,告别中式英语</h5 > <p > 156人学习</p > </div > </div > <div class ="swiper-pagination" > </div > </div > </div > </section >
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 .study_con { padding-bottom : 3.733333rem ; }.study { .study_fo { padding : 0.266667rem ; } .swiper-slide { font-size : 18px ; background : #fff ; width : 7.733333rem ; height : 9.066667rem ; background-color : #fff ; border-radius : 0.266667rem ; box-shadow : 0 0px 10px rgba(0 , 0 , 0 , 0.1 ); h5 { font-size : 0.693333rem ; margin : 0.533333rem 0 ; font-weight : 400 ; padding : 0 0.266667rem ; } p { font-size : 0.693333rem ; color : #ff4400 ; padding : 0 0.266667rem ; } } }
HTML代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <footer class ="footer" > <a href ="#" class ="item" > <img src ="./icons/home.png" alt ="" /> <p > 首页</p > </a > <a href ="#" class ="item" > <img src ="./icons/ms.png" alt ="" /> <p > 模拟面试</p > </a > <a href ="#" class ="item" > <img src ="./icons/net.png" alt ="" /> <p > 技术面试</p > </a > <a href ="#" class ="item" > <img src ="./icons/user.png" alt ="" /> <p > 我的首页</p > </a > </footer >
LESS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 .footer { position : fixed; left : 0 ; bottom : 0 ; height : 2.933333rem ; width : 100% ; z-index : 99999 ; display : flex; padding : 0.533333rem ; background-color : #fff ; border-top : 1px solid #ccc ; .item { flex : 1 ; display : flex; flex-direction : column; align-items : center; img { width : 1.04rem ; height : 1.093333rem ; } p { font-size : 0.586667rem ; color : #666666 ; margin-top : 0.266667rem ; } } }
完整代码:https://gitee.com/yujie-wang/black-horse-noodles
swiper 插件使用 官网地址:https://www.swiper.com.cn/
下载需要的css和js文件 html页面中 引入相关文件
官网找到类似案例,复制html结构,css样式 js 语法
根据需求定制修改模块
图标字体上传下载 上传步骤:
让UI美工准备好 图标字体(必须是svg格式)
点上传按钮(保留颜色并提交)
生成之后加入购物车即可
点击下载 — 下载代码 小技巧: 如何批量下载全部字体图标呢?
1 2 3 4 var span = document .querySelectorAll('.icon-cover' );for (var i = 0 , len = span.length; i < len; i++) { console .log(span[i].querySelector('span' ).click()); }
上传码云并发布部署静态网站 准备工作:
git可以把我们的本地网站提交上传到远程仓库(码云 gitee)里面,类似以前的ftp。码云,就是远程仓库,类似服务器。
码云创建新的仓库。heimamm
利用git 提交 把本地网站提交到码云新建的仓库里面
在网站根目录右键– Git Bash Here
如果是第一次利用git提交,请配置好全局选项1 2 git config --global user.name "用户名" git config --global user.email "你的邮箱地址"
初始化仓库
把本地文件放到暂存区
把本地文件放到本地仓库里面1 git commit -m '提交黑马面面网站'
链接远程仓库1 git remote add origin 你新建的仓库地址
把本地仓库的文件推送到远程仓库 push
码云部署发布静态网站
在当前仓库中,点击“服务”菜单 ;
选择 Gitee Pages
;
选择 “启动” 按钮;
稍等之后,会拿到地址,就可以利用这个地址来预览网页了;
当然你也可以利用草料二维码生成二维码 https://cli.im/
。