【问题标题】:display flex blocks in 3 columns with correct order以正确的顺序在 3 列中显示 flex 块
【发布时间】:2015-04-27 16:51:07
【问题描述】:

是否可以通过 flexbox 或任何其他不涉及将每一列放入包装器的 css 技术来实现?

最佳结果以正确的顺序排列它们,但第 4 个元素位于最长容器下方,而不是其上方的元素下方。

我正在使用指南针,目前我的 scss 是:

  ul.level0 {
    @include display-flex;
    @include flex-flow(row wrap);
    @include justify-content(flex-end);
    @include align-items(flex-start);
    @include align-content(flex-start);

    .menu-group {
      @include display-flex(inline-flex);
      vertical-align: top;
      width: 33.33%;
      margin-bottom: 30px;
      padding: 0 5px;

      li {
        display: block;
        text-align: left;
        margin-bottom: 3px;
      }

      .group-title {
        margin-bottom: 12px;
        text-transform: uppercase;
      }
    }
  }

【问题讨论】:

  • nop,它分成几行并且所有元素的高度相同(最高的行设置高度)
  • 实际上元素高度是正确的,它们没有被拉伸以匹配行高(不适应最大元素)
  • 实际上它与 flex-wrap 和 order ,codepen.io/anon/pen/zxjQLe我的错误:)

标签: css sass flexbox compass


【解决方案1】:

你可以使用 flex-wrap 、 flex-direction 和 order:

ul {
  display:flex;
  flex-direction:column;
  flex-wrap:wrap;
  height:300px;
  margin:1em;
  padding:0;
  list-style-type:none;
}
li {height:80px;
border:solid;
width:30%;
margin:1em;
order:5}
li:nth-child(odd) {
  height:40px;
}
li:first-child {
  height:100%;
}
li:nth-child(1) {
  order:1
}
li:nth-child(2) {
  order:2
}
li:nth-child(3) {
  order:4
}
li:nth-child(4) {
  order:3
}
li:nth-child(5) {
  order:5
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

【讨论】:

  • 有趣,它可以在 codepen 中使用,但不能在我的页面中使用,flex-direction:column;只需将所有 li 元素 1 放在其他 1 列中。
  • @pankijs 那是因为列方向需要明确的高度才能强制换行。
  • 令人遗憾的是,如此好的答案往往得不到认可
  • @NicoO 回答有点用,但在我的情况下它不正确,涉及固定高度,但我需要通用解决方案,因为列高因内容而异,因此没有固定高度。我赞成这个答案,但它不适合我。最终使用 jquery 和绝对位置。 :(
  • @pankijs 你能举一个 html 的例子,内容(假的或真实的)接近你必须处理的吗?
猜你喜欢
  • 1970-01-01
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-16
  • 1970-01-01
相关资源
最近更新 更多