# 响应式布局
@media
width\height 浏览器可视高度、宽度
device-width 设备屏幕宽
通常,面向“移动设备”用户使用max-device-width;面向“PC设备”用户使用max-width
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
.div0{
width: 100%;
height: 500px;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-content: space-evenly;
}
@media screen and (min-device-width :300px){
.div0 div{
width: 30%;
height: 400px;
background-color: orange;
}
}
@media screen and (min-device-width :600px){
.div0 div{
width: 40%;
height: 200px;
background-color: orange;
}
}
</style>
</head>
<body>
<div class="div0">
<div></div>
<div></div>
<div></div>
</div>
</body>
</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
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
@rem
<style type="text/css">
html{
font-size:10px;
}
div{
font-size:1rem; 相对根字体字号
}
</style>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 通过设置flex + @media判断 伸缩布局
<!DOCTYPE html>
<html>
<body>
<div class="div0">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<style type="text/css">
.div0{
width: 100%;
height: 500px;
display: flex;
}
.div0 div:nth-child(1){
background-color: orange;
flex: 0 0 50px;
}
.div0 div:nth-child(2){
background-color: blue;
flex: 1 1 auto;
}
.div0 div:nth-child(3){
background-color: orange;
flex: 0 0 100px;
}
@media screen and (min-width :600px) and (max-width :800px){
.div0 div:nth-child(3){
background-color: green;
}
}
</style>
</body>
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
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
- 使用rem作为单位 多套css解决布局问题
<link rel="stylesheet" media="(min-device-width:300px) and (max-device-width:999px)" href="css1">
<link rel="stylesheet" media="(min-device-width:1000px)" href="css2">
1
2
2