可能的布局?Flexbox vs Float布局,包含多个列和行

mik*_*ans 5 css flexbox

我很好奇这个布局是否可以使用flexbox.我似乎无法解决div 3和4属于#2.浮点数非常简单,只是好奇我是否遗漏了一些可能对flexbox有帮助的属性.

布局

+-------+-------+-------+
| div 1 |     div 2     |
+       +-------+-------+
|       | div 3 | div 4 |
+-------+-------+-------+
Run Code Online (Sandbox Code Playgroud)

标记

<div class="features">
  <div class="feature feature-1">1</div>
  <div class="feature feature-2">2</div>
  <div class="feature feature-3">3</div>
  <div class="feature feature-4">4</div>
</div>
Run Code Online (Sandbox Code Playgroud)

演示

http://codepen.io/mikevoermans/pen/xbWvJJ?editors=110

Ori*_*iol 17

Flexbox不喜欢通过多个列或行扩展的flex项,因为实际上flexbox没有网格概念.

但是,使用一些技巧,您可以实现此布局(以及更复杂的布局):

这是代码:

.features {
  display: flex;
  flex-flow: row wrap;
}
.feature {
  background: #ccc;
  border: 8px solid #fff;
  height: 200px;
  box-sizing: border-box;
  min-width: 0;
  flex: 1;
}
.feature-1 {
  /* Make it taller without increasing the height of the flex line */
  height: 400px;
  margin-bottom: -200px;
}
.features:after {
  /* Force line break */
  content: '';
  width: 100%;
}
.feature-2 ~ .feature {
  /* Place 3 and 4 after the line break */
  order: 1;
}
.feature-3 {
  margin-left: 50%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="features">
  <div class="feature feature-1">1</div>
  <div class="feature feature-2">2</div>
  <div class="feature feature-3">3</div>
  <div class="feature feature-4">4</div>
</div>
Run Code Online (Sandbox Code Playgroud)

但是,修改HTML以便嵌套Flexbox会更容易.

#wrapper {
  height: 400px;
}
.flex {
  display: flex;
}
.column {
  flex-direction: column;
}
.flex > div {
  min-width: 0;
  flex: 1;
}
.item {
  background: #ccc;
  border: 8px solid #fff;
}
Run Code Online (Sandbox Code Playgroud)
<div id="wrapper" class="flex row">
  <div class="item">1</div>
  <div class="flex column">
    <div class="item">2</div>
    <div class="flex row">
      <div class="item">3</div>
      <div class="item">4</div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)