Ângelo Rigo Ângelo Rigo - 7 months ago 217
HTML Question

Flex CSS rowspan 2 and colspan 2

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

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

The first row will have three cells, the last one (cell 3) having a

rowspan = 2


The second row (cell4) having a
colspan = 2
being limited by the cell 3.

I tried this CSS but the
rowspan
atribute did not work.

How can I create this responsive layout format?

.row{
display: flex;
}
.cell{
flex: 1;
background:#eee;
border: 1px solid #444;
padding: 15px;
}


The 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>

Answer

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;
}
<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>