html - 用外部元素中断流

标签 html css flexbox css-float

我有一个 flexbox,其元素显示如下:

enter image description here

问题是:有没有一种方法可以从 flexbox 外部 中断流,以便被阻塞的元素将移动到下一个位置,例如:

enter image description here

flexbox 是某种排序框,所以我不能在里面放置任何其他元素然后进行排序。通常列的高度相同,但有时我需要第一列短一列。

我试过以各种组合方式制作 flow: leftdisplay: inline-block 框,但我无法完成。

.container {
  width: 120px;
  height: 180px;
  margin: 40px 0 0 100px;
}

.flexbox {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: flex-start;
  width: 120px;
  height: 180px;
  background: pink;
}

.inbox {
  width: 50px;
  height: 50px;
  margin: 5px;
  background: purple;
  color: #fff;
  margin-left: auto;
}

.box {
  float: left;
  width: 110px;
  height: 60px;
  margin: -60px 0 0 -60px;
  background: orange;
}
<div class="container">
  <div class="flexbox">
    <div class="inbox"> 1 </div>
    <div class="inbox"> 2 </div>
    <div class="inbox"> 3 </div>
    <div class="inbox"> 4 </div>
    <div class="inbox"> 5 </div>
  </div>
  <div class="box"></div>
</div>

And a fiddle

编辑我只对左下角感兴趣,所以任何技巧都可以。

最佳答案

如果您使用 flex-wrap: wrap-reverse 以及 column-reverse flex directionjustify-content: flex -end 您可以获取配置,但不能获取元素的顺序

请注意,尽管元素的顺序与标记相反 - 请参见下面的演示:

.container {
  width: 120px;
  height: 180px;
  margin: 40px 0 0 100px;
}

.flexbox {
  display: flex;
  flex-direction: column-reverse; /* CHANGED */
  flex-wrap: wrap-reverse; /* CHANGED */
  justify-content: flex-end; /* CHANGED */
  width: 120px;
  height: 180px;
  background: pink;
}

.inbox {
  width: 50px;
  height: 50px;
  margin: 5px;
  background: purple;
  color: #fff;
  margin-left: auto;
}

.box {
  float: left;
  width: 110px;
  height: 60px;
  margin: -60px 0 0 -60px;
  background: orange;
}
<div class="container">
  <div class="flexbox">
    <div class="inbox"> 1 </div>
    <div class="inbox"> 2 </div>
    <div class="inbox"> 3 </div>
    <div class="inbox"> 4 </div>
    <div class="inbox"> 5 </div>
  </div>
  <div class="box"></div>
</div>

关于html - 用外部元素中断流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54749379/

相关文章:

javascript - 如何使用样式和ID动态添加div

html - Rich Faces 日历/css html

html - 当我尝试向我的主要部分添加背景时标题被覆盖

javascript - 使用 JavaScript 压缩包含嵌入图像的 HTML 字符串

html - 为 bg 应用透明渐变叠加和十六进制颜色

php - slimMenu 打破 Z​​en Cart

html - 动态占用空间并使宽度相等

html - 向右浮动在 CSS 中不起作用

html - 容器外的 child

javascript - 当父元素是 contentEditable 时,是否可以防止子元素被删除?