1.使用媒体查询
2.flex布局
3.vm、vh的使用
<!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>
* {
margin: 0;
padding: 0;
}
ul,ol {
list-style: none;
}
/* 以上公共部分 */
/* 一下媒体查询 */
/* PC端 960px以上的媒体查询 */
/* @media screen and (min-width:960px) { 可以简写 */
@media (min-width:960px) {
.part .head {
height: 100px;
width: 100%;
background-color: red;
}
/* PC端center */
.middle .center {
width: 1000px;
margin: 0 auto;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.middle .center>div{
width: 320px;
height: 400px;
margin-top: 20px;
}
.middle .center>div:nth-child(1) {
background-color: purple;
}
.middle .center>div:nth-child(2) {
background-color: blue;
}
.middle .center>div:nth-child(3) {
background-color: pink;
}
.middle .center>div:nth-child(4) {
background-color: green;
}
.middle .center>div:nth-child(5) {
width: 660px;
background-color: orange;
}
}
/* 手机端 500px 以下的媒体 */
@media screen and (max-width:500px){
.part .head {
width: 100vw;
height: 8vh;
background-color: red;
margin-bottom: 2vw;
}
/* 全屏宽度 可以预留两边的空间*/
.part .center {
width: 96vw;
margin: 0 auto;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.d1,.d4,.d5 {
width: 100%;
height: 20vh;
margin-bottom: 2vw;
}
.d2,.d3 {
width: 47vw;
height: 25vh;
margin-bottom: 2vw;
}
.middle .center>div:nth-child(1) {
background-color: purple;
}
.middle .center>div:nth-child(4) {
background-color: green;
}
.middle .center>div:nth-child(5) {
background-color: orange;
}
.middle .center>div:nth-child(2) {
background-color: blue;
}
.middle .center>div:nth-child(3) {
background-color: pink;
}
}
</style>
</head>
<body>
<div class="part">
<div class="head"></div>
<div class="middle">
<div class="center">
<div class="d1"></div>
<div class="d2"></div>
<div class="d3"></div>
<div class="d4"></div>
<div class="d5"></div>
</div>
</div>
</div>
</body>
</html>
效果:
1.移动端模拟效果
2. PC端效果