zoukankan      html  css  js  c++  java
  • css 三列布局

    常用的几种3列布局,即左右两边宽度固定,中间自适应,这也是css面试中大概率会问的问题。

    主要有以下几种方式:

    圣杯布局

    <div class="container">
        <div class="main"></div>
        <div class="sub"></div>
        <div class="extra"></div>
    </div>
    
    .container {
        padding-left: 210px;
        padding-right: 190px;
    }
    .main {
        float: left;
         100%;
        height: 300px;
        background-color: rgba(255, 0, 0, .5);
    }
    .sub {
        position: relative;
        left: -210px;
        float: left;
         200px;
        height: 300px;
        margin-left: -100%;
        background-color: rgba(0, 255, 0, .5);
    }
    .extra {
        position: relative;
        right: -190px;
        float: left;
         180px;
        height: 300px;
        margin-left: -180px;
        background-color: rgba(0, 0, 255, .5);
    }
    

    双飞翼布局

    <div class="main-wrapper">
        <div class="main"></div>
    </div>
    <div class="sub"></div>
    <div class="extra"></div>
    
    .main-wrapper {
        float: left;
         100%;
    }
    .main {
        height: 300px;
        margin-left: 210px;
        margin-right: 190px;
        background-color: rgba(255, 0, 0, .5);
    }
    .sub {
        float: left;
         200px;
        height: 300px;
        margin-left: -100%;
        background-color: rgba(0, 255, 0, .5);
    }
    .extra {
        float: left;
         180px;
        height: 300px;
        margin-left: -180px;
        background-color: rgba(0, 0, 255, .5);
    }
    

    table 布局

    <div class="container">
      <div class="sub"></div>
      <div class="main"></div>
      <div class="extra"></div>
    </div>
    
    .container{
      display: table;
       100%;
      table-layout: fixed;
    }
    .sub{
       180px;
      height: 300px;
      background-color: rgba(0, 255, 0, .5);
      display: table-cell;
    }
    .extra{
       180px;
      height: 300px;
      background-color: #ddd;
      display: table-cell;
    }
    .main{
       100%;
      height: 300px;
      background-color: rgba(255, 0, 0, .5);
      display: table-cell;
    }
    

    flex布局

    .container{
      display: flex;
    }
    .sub{
       180px;
      height: 300px;
      background-color: rgba(0, 255, 0, .5);
    }
    .extra{
       180px;
      height: 300px;
      background-color: #ddd;
    }
    .main{
      flex: 1;
      height: 300px;
      background-color: rgba(255, 0, 0, .5);
    }
    
  • 相关阅读:
    iOS应用崩溃日志分析
    iOS应用崩溃日志分析
    iOS 获取一个类的所有方法
    iOS 获取一个类的所有方法
    UVa 818Cutting Chains (暴力dfs+位运算+二进制法)
    UVa 1374 Power Calculus (IDA*或都打表)
    UVa 10603 Fill (暴力BFS+优先队列)
    HDU 1272 小希的迷宫 (并查集)
    HDU 1060 Leftmost Digit (数学log)
    UVa 1599 Ideal Path (两次BFS)
  • 原文地址:https://www.cnblogs.com/ruomeng/p/9073347.html
Copyright © 2011-2022 走看看