如何使用Flex CSS并模拟rowspan 2和colspan 2

Âng*_*igo 6 html css flexbox

我想使用div构建一个包含2行的响应式布局.

我试试这个jsbin:http://jsbin.com/jiyanayayi/edit?html,css,output

第一行将有三个单元格,最后一行(单元格3)必须有一个单元格 rowspan = 2

具有a的第二行(cell4)colspan = 2必须受到单元3的限制.

我尝试了下面的CSS,但是rowspanatribute不起作用.

如何创建此响应式布局格式?

.row{
  display: flex;
}
.cell{
  flex: 1;
  background:#eee;
  border: 1px solid #444;
  padding: 15px;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<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>
Run Code Online (Sandbox Code Playgroud)

G-C*_*Cyr 11

你还需要使用flex和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*//*
  }
}
*/
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

  • 这个版本似乎导致 Cells 3 和 4 的位置被交换,而不是问题中描述的。`.colspan2` 用在标记中,但不在样式中... (2认同)