# 经典三列式布局

# 圣杯布局

效果图 圣杯布局效果图

代码如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>圣杯布局</title>
  <style>
    body {
      background-color: #666;
    }
    .bd {
      padding: 0px 200px 0 180px;
      height: 100px;
      text-align: center;
      font-family: Arial;
      text-align: center;
    }
    .middle, .left, .right {
      height: 500px;
      float: left;
      position: relative;
      line-height: 500px;
    }
    .middle {
      width: 100%;
      background-color: #f5c531;
    }
    .left {
      width: 180px;
      background-color: #a0c263;
      margin-left: -100%;
      left: -180px;
    }
    .right {
      width: 200px;
      margin-left: -200px;
      background-color: #a0c263;
      right: -200px;
    }
  </style>
</head>
<body>
  <div class="bd">
    <div class="middle">Content</div>
    <aside class="left">left</aside>
    <aside class="right">right</aside>
  </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
38
39
40
41
42
43
44
45
46
47
48
49

# 双飞翼布局

效果图
双飞翼布局效果图

代码如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .wrapper {
      padding: 0;
      overflow: hidden;
      text-align: center;
      line-height: 200px;
    }
    .col {
      float: left;
    }
    .main-wrapper {
      width: 100%;
    }
    .main {
      margin: 0 100px 0 100px;
      height: 200px;
      background-color: #f5c531;
    }
    .left {
      width: 100px;
      height: 200px;
      margin-left: -100%;
      background-color: #a0c263;
    }
    .right {
      width: 100px;
      height: 200px;
      margin-left: -100px;
      background-color: #a0c263;
    }
  </style>
</head>
<body>
  <section class="wrapper">
    <section class="col main-wrapper">
      <section class="main">main</section>
    </section>
    <aside class="col left">left</aside>
    <aside class="col right">right</aside>
  </section>
</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
38
39
40
41
42
43
44
45
46
47
48
  • 圣杯布局和双飞翼布局
  • 三列式布局
    圣杯布局缺点:宽度小于 left 的时候会掉下去
    双飞翼布局解决了圣杯布局的 bug,但缺点是 DOM 树更复杂,渲染性能不如圣杯布局