html 布局,上下各100px,中间自适应

flex

<!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>
      body {
        margin: 0px;
        padding: 0px;
        height: 100vh;
        display: flex;
        flex-direction: column;
      }
      .top,
      .bottom {
        height: 100px;
        background-color: red;
      }
      .center {
        background-color: pink;
        flex: 1;
      }
    </style>
  </head>
  <body>
    <div class="top"></div>
    <div class="center"></div>
    <div class="bottom"></div>
  </body>
</html>

绝对定位

<!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>
      html,
      body {
        margin: 0px;
        padding: 0px;
        height: 100vh;
        position: relative;
        overflow: hidden;
      }
      .top,
      .bottom {
        height: 100px;
        background-color: red;
      }
      .top {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
      }
      .bottom {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
      }
      .center {
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        padding: 100px 0;
      }

      .content {
        height: 100%;
        background-color: blue;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div class="top"></div>
    <div class="center">
      <div class="content"></div>
    </div>
    <div class="bottom"></div>
  </body>
</html>

grid

<!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>
      html,
      body {
        margin: 0px;
        padding: 0px;
        height: 100vh;
        overflow: hidden;
        display: grid;
        grid-template-rows: 100px auto 100px;
      }
      .top,
      .bottom {
        background-color: rgba(255, 0, 0, 0.5);
      }
      .center {
        background-color: blue;
      }
    </style>
  </head>
  <body>
    <div class="top"></div>
    <div class="center"></div>
    <div class="bottom"></div>
  </body>
</html>
posted @ 2020-03-13 17:25  Ajanuw  阅读(384)  评论(0编辑  收藏  举报