How to use Flex CSS and simulate a rowspan 2 and colspan 2

前端 未结 1 778
不知归路
不知归路 2021-02-03 10:33

I want to build a responsive layout with 2 rows using divs .

I try this jsbin: http://jsbin.com/jiyanayayi/edit?html,css,output

The first row will have three ce

相关标签:
1条回答
  • 2021-02-03 11:17

    you need to use also flex and flex-wrap:

    .table {
      display: flex;
      border: solid;
    }
    
    .row {
      flex: 1;
      display: flex;
    }
    
    .row:first-of-type {
      flex-flow: wrap;
    }
    
    .row .rowspan2 {
      flex: 1 1 100%;
    }
    
    .row div {
      border: solid;
      padding: 1em;
      flex: 1;
    }
    
    /* ============================================================== */
    /* if display grid and contents is supported then you may use it  */
    /* ============================================================== */
    /*
    @supports (display:grid) and (display:contents) {
      .table {
        display: grid;
        grid-template-columns: 25% 25% 25% 25%;
        grid-template-areas: "cell1 cell2 cell3 cell3" "cell4 cell4 cell3 cell3";
        border: solid;
      }
      .row {
        display: contents/* hide them in the structure. .row respective children become sibblings *//*
      }
      .row:first-child> :first-child {
        grid-area: cell1;
      }
      .row:first-child div {
        grid-area: cell2;
      }
      .row .cell.rowspan2 {
        grid-area: cell3;
        /*grid-row:span 2; no need if grid-template-area is complete*//*
      }
      div div {
        border: solid;
        padding: 1em;
      }
      .colspan2 {
        grid-area: cell4;
        /*grid-column : span 2; no need if grid-template-area is complete*//*
      }
    }
    */
    <div class="table">
      <div class="row">
        <div class="cell">Cell 1</div>
        <div class="cell">Cell 2</div>
        <div class="cell rowspan2">Cell 3</div>
      </div>
      <div class="row">
        <div class="cell colspan2">Cell 4</div>
      </div>
    </div>

    jsbin updated with @supports uncommented : https://jsbin.com/wexisiyamo/1/edit?html,css,output

    0 讨论(0)
提交回复
热议问题