html页面布局-上中下三栏

2019-04-29  本文已影响0人  麻辣小面瘫
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>
上一篇 下一篇

猜你喜欢

热点阅读