css圣杯布局

54 阅读1分钟
<!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>
    body {
      min-width: 550px;
      /* 假设中间栏最小宽度为 550px */
    }

    #header,
    #footer {
      background-color: #f00;
      color: #fff;
      text-align: center;
      padding: 10px 0;
    }

    #container {
      padding: 0 200px 0 150px;
      /* 中间栏左右 padding,为左右栏留出空间 */
      overflow: hidden;
    }

    #left {
      float: left;
      width: 150px;
      /* 左栏宽度 */
      background-color: #0f0;
      padding: 20px 0;
    }

    #right {
      float: right;
      width: 200px;
      /* 右栏宽度 */
      background-color: #00f;
      padding: 20px 0;
    }

    #middle {
      float: left;
      width: 100%;
      /* 中间栏宽度 100% */
      background-color: #ff0;
      padding: 20px 0;
    }
  </style>
</head>

<body>
  <div id="header">Header</div>
  <div id="container">
    <div id="left">Left</div>
    <div id="middle">Middle</div>
    <div id="right">Right</div>
  </div>
  <div id="footer">Footer</div>
</body>

</html>