html页面布局-上中下三栏

20190429113058.png
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>上中下</title>
  <style>
    html *{
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    html, body{
      width: 100%;
      height: 100%;
    }
    header{
      position: absolute;
      top: 0;
      width: 100%;
      height: 50px;
      background-color: #ff5253;
    }

    main{
      width: 100%;
      min-height: 100%;
      background-color: #999;
      padding-top: 50px;
      font-size: 30px;
      color:#000;
    }
    main div{
      width: 100%;
      height: 400px;
    }
    footer{
      width: 100%;
      height: 80px;
      background-color: blue;
      margin-top: -80px;
    }
  </style>
</head>

<body>
  <header>header头部</header>
  <main>
    <div>1</div>
    <div>1</div>

  </main>
  <footer>
    footer 底部
  </footer>
</body>
</html>

使用calc, vh实现

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>上中下</title>
  <style>
    html *{
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    html, body{
      width: 100%;
      height: 100%;
    }
    header{
      position: absolute;
      top: 0;
      width: 100%;
      height: 50px;
      background-color: #ff5253;
    }

    main{
      width: 100%;
      min-height: calc(100vh - 80px);
      /* background-color: #999; */
      padding-top: 50px;
      font-size: 30px;
      color:#000;
    }
    main div{
      width: 100%;
      height: 400px;
    }
    footer{
      width: 100%;
      height: 80px;
      background-color: blue;
      /* margin-top: -80px; */
    }
  </style>
</head>

<body>

  <header>header头部</header>
  <main>
    这是主体部分
    <div></div>
    
  </main>
  <footer>
    footer 底部(默认置底,页面高度超出一屏幕 footer展示在滚动最下面)
  </footer>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。