Flexbox 3 divs, two columns, one with two rows

I'm trying to take

<div></div>
<div></div>
<div></div>

      

Three consecutive divisions and turn it into below. Where red is div 1, green is div 2, blue is div 3.

I can do it with floats, something like

.div1 { float: left; }
.div2 { float: left; }
.div3 { float: left; }

      

But I can't get it to work in flexbox, is this possible?

enter image description here

+8


source to share


2 answers


Khakish Method (just for fun):
* Not recommended (I'm sure you'll notice why)

.flex-body {
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-content: stretch;
    align-items: stretch;
    transform: rotate(90deg);
    max-width: 500px;
    margin: auto;
}

.flex-body div {
    border: 1px solid white;
    height: 300px;
    flex: 1 1 200px;
}

.flex-body div:last-of-type {
    flex: 1 1 300px;
    height: 300px;
}
      

<div class="flex-body">
  <div style="background: #0980cc;"></div>
  <div style="background: #09cc69;"></div>
  <div style="background: #cc092f;"></div>
</div>
      

Run codeHide result




Legit Method:
* Recommended

.flex-row {
    flex-direction: row;
    display: flex;
}

.flex-column {
    flex-direction: column;
    display: flex;
}

.flex-body {
    display: flex;
}

.flex-body div:not([class*="flex"]) {
    border: 1px solid white;
    flex: 1 1 200px;
    width: 300px;
}
      

<div class="flex-body">
  <div class="flex-row">
    <div style="background: #0980cc;"></div>
  </div>
  <div class="flex-column">
    <div style="background: #09cc69;"></div>
    <div style="background: #cc092f;"></div>
  </div>
</div>
      

Run codeHide result


+13


source


Thinking about it a little more, it's possible with flexbox. The container just needs to have a specific height ( %

, px

or vh

) will work.

http://www.codeply.com/go/U1DCKAx85d



body {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  height: 100vh;
}

.a {
  flex: 0 0 100%;
  background: red;
}

.b, .c {
  flex: 0 0 50%;
  background: green;
}

.c {
  background: blue;
}

      

http://www.codeply.com/go/U1DCKAx85d



+5


source







All Articles