Flex Grid

by Kevin Pliester

HTML

<!-- TEST -->
<div class="row">
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
  <div class="col">
    Test
  </div>
</div>

CSS

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body,
html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.row {
  width: 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: flex-start;
}

.row::after {
  content: "";
  clear: both;
  display: table;
}

.col {
  flex: 1 25%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  color: #666;
  padding: 15px;
  min-height: 200px;
  background-color: #ddd;
}

@media (max-width: 1200px) {
  .row {
    justify-content: space-around;
  }
  .col {
    flex: 1 33.333333%;
  }
}

@media (max-width: 800px) {
  .row {
    justify-content: space-around;
  }
  .col {
    flex: 1 50%;
  }
}

@media (max-width: 500px) {
  .row {
    flex-direction: column;
  }
  .col {
    flex: 1 100%;
  }
}