Home > Web Front-end > CSS Tutorial > Five common page layouts in css

Five common page layouts in css

王林
Release: 2020-08-14 17:11:43
forward
3298 people have browsed it

Five common page layouts in css

Public style part code:

(Recommended tutorial: CSS tutorial)

    html * {
      margin: 0;
      padding: 0;
    }
    .layout {
      margin-bottom: 20px;
    }
    .layout article {
      width: 100%;
     }
    .layout article > div {
      min-height: 100px;
    }
    .layout article .left {
      width: 300px;
      background: red;
    }
    .layout article .center {
      background: orange;
    }
    .layout article .right {
      width: 300px;
      background: blue;
    }
Copy after login

float layout

  <!-- 浮动布局 -->
  <section class="layout float">
    <style>
      .layout.float .left {
        float: left;
      }
      .layout.float .right {
        float: right;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="right"></div>
      <div class="center">
        <h2>这是float布局</h2>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
    </article>
  </section>
Copy after login

absolute layout

 <!-- 定位布局 -->
  <section class="layout absolute">
    <style>
      .layout.absolute .left-center-right > div {
        position: absolute;
      }
      .layout.absolute .left {
        left: 0;
      }
      .layout.absolute .center {
        left: 300px;
        right: 300px;
      }
      .layout.absolute .right {
        right: 0;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>这是absolute布局</h2>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
Copy after login

flex layout

  <!-- flex布局 -->
  <section class="layout flex">
    <style>
      .layout.flex {
        margin-top: 140px;
      }
      .layout.flex .left-center-right{
        display: flex;
      }
      .layout.flex .center {
        flex: 1;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>这是flex布局</h2>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
Copy after login

table layout

  <!-- table布局 -->
  <section class="layout table">
    <style>
      .layout.table .left-center-right {
        display: table;
        height: 100px;
      }
      .layout.table .left-center-right > div{
        display: table-cell;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>这是table布局</h2>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
Copy after login

grid layout

  <!-- grid布局 -->
  <section class="layout grid">
    <style>
      .layout.grid .left-center-right {
        display: grid;
        grid-template-columns: 300px auto 300px;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>这是grid布局</h2>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
Copy after login

The above is the detailed content of Five common page layouts in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template