flex布局案例-圣杯布局
# flex布局案例-圣杯布局
可用F12开发者工具查看元素及样式,可打开codepen在线编辑代码。
::: demo [vanilla]
<html>
<div class="HolyGrail">
<header>#header</header>
<div class="wrap">
<nav class="left">left 宽度固定200px</nav>
<main class="content">center 宽度自适应</main>
<aside class="right">right 宽度固定200px</aside>
</div>
<footer>#footer</footer>
</div>
</html>
<style>
.HolyGrail {
text-align: center;
display: flex;
min-height: 40vh;
flex-direction: column;
}
.HolyGrail .wrap {
display: flex;
flex: 1;
}
.HolyGrail .content {
background: #eee;
flex: 1;
}
.HolyGrail .left,.HolyGrail .right {
background:lightgreen;
flex: 0 0 200px;
}
.HolyGrail header,.HolyGrail footer{
background:#999;
height: 50px;
line-height: 50px;
}
.HolyGrail .left {
background:salmon;
}
</style>
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
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
:::
参考:http://www.ruanyifeng.com/blog/2015/07/flex-examples.html (opens new window)
上次更新: 2024/12/05, 17:14:06