-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.html
120 lines (109 loc) · 2.57 KB
/
demo2.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用flex实现,侧栏固定宽度</title>
<style>
html, body, p {
padding: 0;
margin: 0;
}
section {
display: flex;
flex: 1;
flex-wrap: wrap;
}
section div {
flex: 1;
}
.header {
height: 70px;
background: red;
}
.footer {
height: 70px;
background: #808080;
}
.sidebar {
flex: 0 0 200px; /* 固定宽度,不需要缩放 */
height: 300px;
background: green;
}
.ads {
height: 200px;
background: #DDDDDD;
}
.conve {
flex: 0 0 100px; /* 固定宽度,不需要缩放 */
height: 300px;
background: yellow;
}
.main {
height: 100px;
color: #fff;
background: black;
}
.inner-box {
display: flex;
flex: 1;
flex-wrap: wrap;
}
.inner-box .nav {
flex: 1 0 100%;
height: 100px;
background: orange;
}
.inner-box .conve {
flex: 0 0 200px;
}
.inner-box .ads {
flex-grow: 1;
}
.inner-main {
display: flex;
flex: 1;
flex-direction: column;
}
.inner-main .main {
margin-left: -200px; /* 200px是sidebar的width */
}
</style>
</head>
<body>
<div class="header"><p>header</p></div>
<section>
<div class="sidebar">
<p>sidebar</p>
<p>固定宽度,200px</p>
<p>nav,ads, conve, main都属于子容器inner-box</p>
</div>
<!-- inner-box整个容器会自适应sidebar之外的空间 -->
<div class="inner-box">
<div class="nav">
<p>nav</p>
<p>父容器为inner-box, 自适应宽度,占满inner-box的一行</p>
<p>ads, main属于孙容器inner-main</p>
</div>
<!-- 由于为父容器inner-box设置了换行,nav占了一行,所以inner-main会换行 -->
<!-- 占满除去conve固定宽度的其余空间 -->
<div class="inner-main">
<div class="ads">
<p>ads</p>
<p>自适应宽度,在容器inner-main中,设置了垂直布局,所以ads会占满这一行</p>
</div>
<div class="main">
<p>main</p>
<p>main在容器inner-main中,所以填满也只有inner-main的宽度(也就是和ads一样宽),设置其margin-left为
sidebar的宽度的负值,自身自适应宽度,就可以填补sidebar下面的空白区,达到效果</p>
</div>
</div>
<!-- 和inner-main在同一行 -->
<div class="conve">
<p>conve</p>
<p>固定宽度,200px</p>
</div>
</div>
</section>
<div class="footer"><p>footer</p></div>
</body>
</html>