静态页面,学习目标是实现移动端不同屏幕适配
html
<!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 ,maximum-scale=1.0,minimum-scale=1.0, user-scalable=no">
<title>益康问答</title>
<link rel="stylesheet" href="./css/normalize.css">
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<!-- 头部部分 -->
<header>
<a href="#"><span></span>返回</a>
<span>益康问答</span>
<a href="#"></a>
</header>
<!-- 导航栏部分 -->
<div class="nav">
<div>问题榜</div>
<div></div>
<div>新晋榜</div>
<div></div>
<div>才华榜</div>
</div>
<!-- 轮播图部分 -->
<div class="banner">
<img src="./images/banner.jpg" alt="">
</div>
<!-- 内容部分 -->
<div class="mid_con">
<p>如何学习语文的文言文内容,快速提高语文成
绩?</p>
<div>
<span>王知易</span>
<span>英语文学语言老师</span>
</div>
<div>
<span></span>
<span>限时免费听</span>
<span>22人听过</span>
</div>
</div>
<div class="mid_con">
<p>如何学习语文的文言文内容,快速提高语文成
绩?</p>
<div>
<span>王知易</span>
<span>英语文学语言老师</span>
</div>
<div>
<span></span>
<span>限时免费听</span>
<span>22人听过</span>
</div>
</div>
<div class="mid_con">
<p>如何学习语文的文言文内容,快速提高语文成
绩?</p>
<div>
<span>王知易</span>
<span>英语文学语言老师</span>
</div>
<div>
<span></span>
<span>限时免费听</span>
<span>22人听过</span>
</div>
</div>
<div class="mid_con">
<p>如何学习语文的文言文内容,快速提高语文成
绩?</p>
<div>
<span>王知易</span>
<span>英语文学语言老师</span>
</div>
<div>
<span></span>
<span>限时免费听</span>
<span>22人听过</span>
</div>
</div>
<!-- 底部导航部分 -->
<div class="foots">
<div>榜单</div>
<div>收听</div>
<div>发现</div>
<div>我的</div>
</div>
</body>
</html>
CSS(less)
//引入公共样式
@import url(./common.less);
//字体声明
@font-face {
font-family: 'icomoon';
src: url('../fonts/icomoon.eot?tomleg');
src: url('../fonts/icomoon.eot?tomleg#iefix') format('embedded-opentype'),
url('../fonts/icomoon.ttf?tomleg') format('truetype'),
url('../fonts/icomoon.woff?tomleg') format('woff'),
url('../fonts/icomoon.svg?tomleg#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
// 根据设计稿设置基础字体大小
@basefont: 42.66666667px;
// body初始化
body {
min-width: (320rem / @basefont);
width: 15rem;
margin: 0 auto;
font-family: 'Times New Roman', Times, serif;
background-color: #ebebeb;
font-size: (26rem / @basefont);
}
// 头部部分
header {
display: flex;
justify-content: space-between;
font-family: 'icomoon';
background-color: #44b181;
width: 15rem;
height: (80rem / @basefont);
margin: 0 auto;
text-align: center;
line-height: (80rem / @basefont);
padding: 0 (20rem / @basefont);
position: fixed;
top: 0;
z-index: 1;
a {
color: #fff;
&:nth-child(1) {
position: relative;
padding-left: (25rem / @basefont);
font-size: (27rem / @basefont);
span {
position: absolute;
top: (3rem / @basefont);
left: (-15rem / @basefont);
font-size: (50rem / @basefont);
}
}
&:nth-child(3) {
width: (52rem / @basefont);
height: (12rem / @basefont);
padding: (40rem / @basefont) 0;
background: url(../images/more_icon.png) no-repeat center center;
background-size: (52rem / @basefont) auto;
}
}
>span {
flex: 1;
color: #fff;
font-size: (38rem / @basefont);
}
}
//导航栏部分
.nav {
display: flex;
padding: (28rem / @basefont) (20rem / @basefont) 0;
// margin-bottom: (28rem / @basefont) ;
height: (87rem / @basefont);
width: 15rem;
background-color: #fff;
text-align: center;
position: fixed;
top: (80rem / @basefont);
z-index: 1;
>div {
color: #000;
&:nth-child(2n+1) {
flex: 1;
padding-bottom: (28rem / @basefont);
}
&:nth-child(1) {
color: #44b181;
border-bottom: (2rem / @basefont) solid #44b181;
}
&:nth-child(2n) {
border-right: 1px solid #e1e1e1;
height: (24rem / @basefont);
}
&:nth-child(5) {
position: relative;
}
&:nth-child(5)::after {
position: absolute;
right: 0;
top: 0;
height: (33rem / @basefont);
width: (33rem / @basefont);
background-color: pink;
content: '';
display: table;
background: url(../images/sprites.png) no-repeat 0 0;
background-size: (289rem / @basefont) auto;
}
}
}
//轮播图部分
.banner {
height: (300rem / @basefont);
width: 15rem;
img {
width: 100%;
}
}
// 内容部分
.mid_con {
margin-top: (20rem / @basefont);
height: (253rem / @basefont);
background-color: #fff;
padding: (20rem / @basefont);
p {
width: (537rem / @basefont);
font-size: (26rem / @basefont);
font-weight: 700;
margin-bottom: (20rem / @basefont);
}
div {
&:nth-child(2) {
font-size: (20rem / @basefont);
color: #999;
margin-bottom: (30rem / @basefont);
span {
&:first-child {
padding-right: (20rem / @basefont);
margin-right: (20rem / @basefont);
border-right: 1px solid #666;
}
}
}
&:nth-child(3) {
display: flex;
justify-content: space-between;
align-items: flex-end;
height: (80rem / @basefont);
span {
&:nth-child(1) {
display: inline-block;
width: (80rem / @basefont);
height: (80rem / @basefont);
background: url(../images/tou.png) no-repeat;
background-size: (80rem / @basefont) auto;
margin-right: 30px;
}
&:nth-child(2) {
display: inline-block;
width: (289rem / @basefont);
height: (60rem / @basefont);
background: url(../images/sprites.png) no-repeat 0px (-56rem / @basefont);
background-size: (400rem / @basefont) auto;
line-height: (60rem / @basefont);
color: #fff;
padding-left: (55rem / @basefont);
flex: 1;
position: relative;
}
&:nth-child(2)::before {
content: '';
display: table;
width: (20rem / @basefont);
height: (28rem / @basefont);
background: url(../images/sprites.png) no-repeat (-110rem / @basefont) 0;
background-size: (400rem / @basefont) auto;
position: absolute;
left: (20rem / @basefont);
top: (15rem / @basefont);
}
&:nth-child(3) {
color: #999999;
font-size: (20rem / @basefont);
position: relative;
}
&:nth-child(3)::before {
content: '';
display: table;
width: (24rem / @basefont);
height: (21rem / @basefont);
background: url(../images/sprites.png) no-repeat (-64rem / @basefont) 0;
background-size: (400rem / @basefont) auto;
position: absolute;
top: (0rem / @basefont);
left: (-30rem / @basefont);
}
}
}
}
}
// 底部导航部分
.foots {
position: fixed;
bottom: 0;
display: flex;
z-index: 1;
background-color: #f5f7f9;
height: (100rem / @basefont);
text-align: center;
div {
flex: 1;
width: (160rem / @basefont);
position: relative;
padding-top: (60rem / @basefont);
&:nth-child(1) {
color: #44b181;
}
&:nth-child(1)::before {
content: '';
display: table;
width: (32rem / @basefont);
height: (27rem / @basefont);
background: url(../images/sprites.png) no-repeat (-1rem / @basefont) (-140rem / @basefont);
background-size: (400rem / @basefont) auto;
position: absolute;
left: (64rem / @basefont);
top: (18rem / @basefont);
}
&:nth-child(2)::before {
content: '';
display: table;
width: (34rem / @basefont);
height: (27rem / @basefont);
background: url(../images/sprites.png) no-repeat (-35rem / @basefont) (-140rem / @basefont);
background-size: (400rem / @basefont) auto;
position: absolute;
left: (64rem / @basefont);
top: (18rem / @basefont);
}
&:nth-child(3)::before {
content: '';
display: table;
width: (32rem / @basefont);
height: (32rem / @basefont);
background: url(../images/sprites.png) no-repeat (-71rem / @basefont) (-137rem / @basefont);
background-size: (400rem / @basefont) auto;
position: absolute;
left: (64rem / @basefont);
top: (18rem / @basefont);
}
&:nth-child(4)::before {
content: '';
display: table;
width: (30rem / @basefont);
height: (33rem / @basefont);
background: url(../images/sprites.png) no-repeat (-107rem / @basefont) (-137rem / @basefont);
background-size: (400rem / @basefont) auto;
position: absolute;
left: (64rem / @basefont);
top: (18rem / @basefont);
}
}
}
公共样式
a {
text-decoration: none;
}
input {
outline: 0;
vertical-align: middle;
-webkit-appearance: none;
}
a,img,input {
-webkit-touch-callout: none;
}
ul li {
list-style: none;
}
img {
border: 0px;
vertical-align: middle;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 50px;
}
@num:15;
//320px
@media screen and (min-width:320px) {
html {
font-size: (320px / @num);
}
}
//360px
@media screen and (min-width:360px) {
html {
font-size: (360px / @num);
}
}
//375px
@media screen and (min-width:375px) {
html {
font-size: (375px / @num);
}
}
//384px
@media screen and (min-width:384px) {
html {
font-size: (384px / @num);
}
}
//400px
@media screen and (min-width:400px) {
html {
font-size: (400px / @num);
}
}
//414px
@media screen and (min-width:414px) {
html {
font-size: (414px / @num);
}
}
//424px
@media screen and (min-width:424px) {
html {
font-size: (424px / @num);
}
}
//480px
@media screen and (min-width:480px) {
html {
font-size: (480px / @num);
}
}
// 540px
@media screen and (min-width:540px) {
html {
font-size: (540px / @num);
}
}
// 640px
@media screen and (min-width:640px) {
html {
font-size: (640px / @num);
}
}
// 720px
@media screen and (min-width:720px) {
html {
font-size: (720px / @num);
}
}
//750px
@media screen and (min-width:750px) {
html {
font-size: (750px / @num);
}
}