温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css中常见页面布局有哪些

发布时间:2020-08-15 10:35:08 来源:亿速云 阅读:135 作者:小新 栏目:web开发

这篇文章主要介绍css中常见页面布局有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

公共样式部分代码:

    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;
    }

float布局

  <!-- 浮动布局 -->
  <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">
        <h3>这是float布局</h3>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
    </article>
  </section>

absolute布局

 <!-- 定位布局 -->
  <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">
        <h3>这是absolute布局</h3>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>

flex布局

  <!-- 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">
        <h3>这是flex布局</h3>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>

table布局

  <!-- 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">
        <h3>这是table布局</h3>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>

grid布局

  <!-- 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">
        <h3>这是grid布局</h3>
        <p>这是一段文字</p>
        <p>这是一段文字</p>
      </div>
      <div class="right"></div>
    </article>
  </section>

以上是css中常见页面布局有哪些的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI