• css布局


    一列定宽,一列自适应

    1、float + margin 

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right-fix">
        <div class="right">
          <p>right</p>
          <p>right</p>
        </div>
      </div>
    </div>
     
    <style>
      .left {
        float: left;
        width: 100px;
      }
      .right-fix {
        float: right;
        width: 100%;
        margin-left: -100px;
      }
      .right {
        margin-left: 100px
        /*间距可再加入 margin-left */
      }
    </style>

    2、float + overflow--不支持 IE 6

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .left {
        float: left;
        width: 100px;
      }
      .right {
        overflow: hidden;
      }
    </style>

    3、table

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .parent {
        display: table;
        width: 100%;
        table-layout: fixed;
      }
      .left {
        display: table-cell;
        width: 100px;
      }
      .right {
        display: table-cell;
        /*宽度为剩余宽度*/
      }
    </style>

    4、flex

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .parent {
        display: flex;
      }
      .left {
        width: 100px;
        margin-left: 20px;
      }
      .right {
        flex: 1;
      }
    </style>

    等分布局

    1. float--兼容 IE8 以上版本

    <div class="parent">
      <div class="column">
        <p>1</p>
      </div>
      <div class="column">
        <p>2</p>
      </div>
      <div class="column">
        <p>3</p>
      </div>
      <div class="column">
        <p>4</p>
      </div>
    </div>
    <style>
      .parent {
        margin-left: -20px;
      }
      .column {
        float: left;
        width: 25%;
        padding-left: 20px;
        box-sizing: border-box;
      }

    2、table

    <div class='parent-fix'>
      <div class="parent">
        <div class="column">
          <p>1</p>
        </div>
        <div class="column">
          <p>2</p>
        </div>
        <div class="column">
          <p>3</p>
        </div>
        <div class="column">
          <p>4</p>
        </div>
      </div>
    </div>
     
    <style>
      .parent-fix {
        margin-left: -20px;
      }
      .parent {
        display: table;
        width: 100%;
        /*可以布局优先,也可以单元格宽度平分在没有设置的情况下*/
        table-layout: fixed;
      }
      .column {
        display: table-cell;
        padding-left: 20px;
      }
    </style>

    等高布局

    1.table

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .parent {
        display: table;
        width: 100%;
        table-layout: fixed;
      }
      .left {
        display: table-cell;
        width: 100px;
      }
      .right {
        display: table-cell
        /*宽度为剩余宽度*/
      }
    </style>

    2.flex--使用了 align-items: stretch,flex 默认的 align-items 的值为 stretch

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .parent {
        display: flex;
      }
      .left {
        width: 100px;
        margin-left: 20px;
      }
      .right {
        flex: 1;
      }
    </style>

    3. float

    <div class="parent">
      <div class="left">
        <p>left</p>
      </div>
      <div class="right">
        <p>right</p>
        <p>right</p>
      </div>
    </div>
     
    <style>
      .parent {
        overflow: hidden;
      }
      .left,
      .right {
        padding-bottom: 9999px;
        margin-bottom: -9999px;
      }
      .left {
        float: left;
        width: 100px;
        margin-right: 20px;
      }
      .right {
        overflow: hidden;
      }
    </style>
  • 相关阅读:
    转载--详解tomcat配置
    MongoDB@入门一
    面试@单例模式
    单点登录系统(一)
    SublimeText3 初探(工欲善其事,必先利其器)
    UEFI+GPT 修复 win10启动
    悟空模式-java-建造者模式
    悟空模式-java-原型模式
    悟空模式-java-单例模式
    悟空模式-java-抽象工厂模式
  • 原文地址:https://www.cnblogs.com/zsy0712/p/6991407.html
Copyright © 2020-2023  润新知