<h1><a href="http://www.zhihu.com/question/28542816" traget="_blank">flex 实现栅格布局</a></h1>

<section class="flex demo">
  <section class="a">a</section>
  <section class="b">b</section>
  <section class="c">c</section>
  <section class="d">d</section>
  <section class="e">e</section>
</section>

<section class="flex row demo">
  <section class="a">a</section>
  <section class="b">b</section>
  <section class="c">c</section>
  <section class="d">d</section>
  <section class="e">e</section>
</section>
* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
h1,
h2 {
  text-align: center;
  color: #555;
}
.demo {
  width: 620px;
  height: 310px;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 20px;
}
.demo section {
  margin-bottom: 10px;
  margin-right: 10px;
  border-radius: 9px;
  border: 1px solid blue;
  background-color: #66B2EC;
  color: #fff;
  font-size: 36px;
  text-transform: uppercase;
  line-height: 150px;
}
/* flex */

.flex {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: space-between;
  justify-content: space-between;
}
.flex section {
  width: 200px;
  height: 150px;
  margin: 0;
}
.flex .a {
  height: 100%;
}
.flex .c {
  order: 4;
}
.flex .d {
  order: 3;
}
.flex .e {
  order: 5;
}

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

.flex.row section {
  order: 0;  background: #92b8de;
}

.flex.row .a {
  height: 150px;
  width: 410px;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.