zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    android在开发过程中的数据库存储位置
    JSONArray的初始化的形式
    Android中asset文件夹与raw文件夹的区别深入解析(转)
    Android 建立Menu选单&&onOptionsItemSelected (转)
    onItemLongClick+onCreateContextMenu实现长按ListItem弹出不同菜单
    thrift框架
    64 位 win7 使用PLSQL Developer(转)
    Java-->服务器的响应(Servlet--doGet&doPost)
    JAVA printWriter中write()和println()区别
    JavaWeb学习总结(六)—HttpServletResponse
  • 原文地址:https://www.cnblogs.com/zsy0712/p/6991407.html
Copyright © 2011-2022 走看看