The holy grail layout

<! doctypehtml>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="Width =device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .container {
      padding-left: 200px;
      padding-right: 200px;
    }

    .left {
      float: left;
      width: 200px;
      height: 400px;
      background: red;
      margin-left: -100%;
      position: relative;
      left: -200px;
    }

    .center {
      float: left;
      width: 100%;
      height: 400px;
      background: yellow;
    }

    .right {
      float: left;
      width: 200px;
      height: 400px;
      background: blue;
      margin-left: -200px;
      position: relative;
      right: -200px;
    }
  </style>
</head>
<body>
<section class="container">
  <div class="center"></div>
  <div class="left"></div>
  <div class="right"></div>
</section>
</body>
</html>
Copy the code

steps

  • writecenterPart,width 100%
  • center.left.rightBoth float to the left
  • The parent containercontainerSet up thepadding-leftandpadding-right
  • Set up themargin-leftNegative letleftandrightPartial return tocenterPart of the same line
  • Set relative positioning, letleftandrightMove the parts to the sides

disadvantages

  • The minimum width of the center section cannot be less than the width of the left section
  • The height of one column is elongated, and the height of the other two columns is not automatically filled

Twin wing layout

<! doctypehtml>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="Width =device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>* {padding: 0;
      margin: 0;
    }
    .container {
      min-width: 600px;
    }
    .left {
      float: left;
      width: 200px;
      height: 400px;
      background: red;
      margin-left: -100%;
    }
    .center {
      float: left;
      width: 100%;
      height: 400px;
      background: yellow;
    }
    .center .inner {
      margin: 0 200px;
    }
    .right {
      float: left;
      width: 200px;
      height: 400px;
      background: blue;
      margin-left: -200px;
    }
  </style>
</head>
<body>
<section class="container">
  <div class="center">
    <div class="inner">Twin wing layout</div>
  </div>
  <div class="left"></div>
  <div class="right"></div>
</section>
</body>
</html>
Copy the code

steps

  • writecenterPart,width 100%
  • center.left.rightBoth float to the left
  • centerAdd an inner layer to the sectiondivAnd set upmargin-left.margin-right
  • Set up themargin-leftNegative letleftandrightPartial return tocenterPart of the same line

disadvantages

  • Add a layer ofdomTree node

conclusion