Basic // page layout-two-column layout 3


1. Topic

Give your answer based on the question.
(The upper height is fixed, the lower is adaptive)
Topic: The upper height is fixed at 150px, and the lower is adaptive.

Second, my code details

https://codepen.io/janmie-cjm/pen/QWNBYgP

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面布局-两栏布局3</title>
  <style>
    html *{
     
     
      margin: 0;
      padding: 0;
    }
    body{
     
     
      background: #ffccee;
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
<!-- 上高度固定150px,下自适应 -->
  <!-- 1-绝对定位 -->
  <!-- <section>
    <style>
      .top1 {
        background: #aee;
        width: 100%;
        height: 150px;
        top: 0;
        position: absolute;
      }
      .bottom1 {
        background: #eaa;
        width: 100%;
        height: 100%;
        top: 150px;
        position: absolute;
      }
    </style>
    <article class="wrapper1">
      <div class="top1">我是上栏</div>
      <div class="bottom1">我是下栏</div>
    </article>
  </section> -->

  <!-- 2-flexbox -->
  <!-- <section class="wrapper2">
    <style>
      body,section,article {
        display: flex;
        flex-direction: column;
        height: 100vh;
        width: 100%;
      }
      .top2 {
        background: #aee;
        width: 100%;
        height: 150px;
      }
      .bottom2 {
        background: #eaa;
        width: 100%;
        flex: 1;
      }
    </style>
    <article>
      <div class="top2">我是上栏</div>
      <div class="bottom2">我是下栏</div>
    </article>
  </section> -->

  <!-- 3-table -->
  <!-- <section>
    <style>
      .wrapper3 {
        display: table;
        width: 100%;
        height: 100vh;
      }
      .wrapper3>div {
        display: table-row;
      }
      .top3 {
        background: #aee;
        width: 100%;
        height: 150px;
      }
      .bottom3 {
        background: #eaa;
        width: 100%;
      }

    </style>
    <article class="wrapper3">
      <div class="top3">我是上栏</div>
      <div class="bottom3">我是下栏</div>
    </article>
  </section> -->

  <!-- 4-grid -->
  <section>
    <style>
      .wrapper4 {
     
     
        display: grid;
        grid-template-columns: auto;
        grid-template-rows: 150px auto;
        width: 100%;
        height: 100vh;
      }
      .top4 {
     
     
        background: #aee;
        width: 100%;
      }
      .bottom4 {
     
     
        background: #eaa;
        width: 100%;
      }

    </style>
    <article class="wrapper4">
      <div class="top4">我是上栏</div>
      <div class="bottom4">我是下栏</div>
    </article>
  </section>
</body>
</html>

Three, summary

  1. What are the solutions to this problem?
    Absolute positioning / flexbox / table layout / grid layout;

  2. The advantages and disadvantages of each program?
    1) Absolute positioning
    Excellent: Simple Shortage : Break
    away from the document flow, need to combine with BFC application, more code
    2) Excellent flexbox
    : Simple and fast, good compatibility
    3) Table layout
    Excellent: Good compatibility Shortage : The
    height of each column will change at the same time ; The table needs to be rendered first, and the page generation speed is delayed.
    4) Grid layout.
    Excellent: It can realize the two-dimensional complex operation with multiple rows and multiple columns, with better compatibility and simplified code

  3. Are there any compatible solutions?
    flexbox, grid layout

note! ! ! The up and down layout spreads the entire page, generally the outermost height is set to height = 100vh.


*There are still many shortcomings in the code. We hope to put forward different opinions and communicate with each other. *

Guess you like

Origin blog.csdn.net/weixin_37877794/article/details/108625901