Flexbox Layout layout: 5 square (1 large, 4 small)

I am trying to assemble a flexbox layout - for the purposes of this question I will call it a “square five blocks” layout (see image), but I ran into difficulties, since all the experiments I tried did not wrap correctly.

I saw the same layout that was made using float, but I was hoping it would be a bit later, and use a more modern method - hence flexbox. I tried to search for this template, but there is no consistent name for it, so searching for similar examples proves its strength.

I also use view units to ensure that the blocks remain absolutely square, all based on viewport width units (vw).

div { width: 25vw; height: 25vw; }
div:first-of-type { width: 50vw; height: 50vw; }

Key features are that all blocks must be square; the first block must be the size of the remaining four combined. Has anyone seen or worked on such a layout before?

5-block grid of perfect squares using flexbox;  the first block must be the exact size of the remaining four blocks

Thank!!

+4
source share
2 answers

Nested flexboxes will work here in conjunction with the media.

Codepen Demo with Media Request

Basically:

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.parent {
  width: 100vw;
  display: flex;
}
.col {
  flex: 0 0 50vw;
  height: 50vw;
  background: blue;
}
.wrap {
  display: flex;
  flex-wrap: wrap
}
.box {
  flex: 0 0 25vw;
  height: 25vw;
}
.red {
  background: red;
}
.pink {
  background: pink;
}
.orange {
  background: orange;
}
.grey {
  background: grey;
}
<div class="parent">
  <div class="col"></div>
  <div class="col wrap">
    <div class="box red"></div>
    <div class="box pink"></div>
    <div class="box orange"></div>
    <div class="box grey"></div>
  </div>
</div>
Run codeHide result
+3
source

See the code below and expand the result. I used flexbox

body {
  margin: 0;
  height: 100vh;
  width: 100vw;
}

.wrapper {
  height: 100%;
}

.layout.horizontal,
.layout.vertical {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

.layout.horizontal {
  -ms-flex-direction: row;
  -webkit-flex-direction: row;
  flex-direction: row;
}

.layout.vertical {
  -ms-flex-direction: column;
  -webkit-flex-direction: column;
  flex-direction: column;
}

.flex {
  -ms-flex: 1 1 0.000000001px;
  -webkit-flex: 1;
  flex: 1;
  -webkit-flex-basis: 0.000000001px;
  flex-basis: 0.000000001px;
}

.box {
  color: #fff;
  text-align: center;
}

.box.blue {
  background: #312783;
}

.box.green {
  background: #0B983A;
}

.box.yellow {
  background: #E1BD48;
}

.box.pink {
  background: #D2007F;
}

.box.orange {
  background: #EB6053;
}

@media all and (max-width: 768px) {
  .change-in-responsive.layout.horizontal {
    -ms-flex-direction: column;
    -webkit-flex-direction: column;
    flex-direction: column;
  }
}
<div class="layout horizontal wrapper change-in-responsive">
  <div class="box large flex blue">1</div>
  <div class="flex layout vertical">
    <div class="flex layout horizontal">
      <div class="box green flex">2</div>
      <div class="box yellow flex">3</div>
    </div>
    <div class="flex layout horizontal">
      <div class="box pink flex">4</div>
      <div class="box orange flex">5</div>
    </div>
  </div>
</div>
Run codeHide result
+2
source

All Articles