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>
  • 相关阅读:
    centos7之添加开机启动服务/脚本
    高性能 Windows C++ 通用组件 VCLogger v2.0.3 正式发布
    Kerberos认证流程
    使用Spring.Net+NHibernate构建WCF应用
    国家重点基础研究发展计划和重大科学研究计划方向
    项目实现思路(不断更新)
    LINQ新特性简介及入门教程
    XXX公司CRM项目开发日志
    GridView的增删改查和分页
    团队开发之环境搭建
  • 原文地址:https://www.cnblogs.com/zsy0712/p/6991407.html
Copyright © 2011-2022 走看看