【问题标题】:"rowspan" behavior with flexboxflexbox 的“rowspan”行为
【发布时间】:2014-12-23 19:53:26
【问题描述】:

鉴于此标记:

<div class="foo">
    <div class="a"></div>
    <div class="b"></div>
    <div class="c"></div>
</div>

还有 CSS:

.foo {
    display: flex;
    flex-wrap: wrap;
}

.a {
    flex: none;
    width: 50%;
    height: 100px;
    background: green;
}

.b {
    flex: none;
    width: 50%;
    height: 200px;
    background: blue;
}

.c {
    flex: none;
    width: 50%;
    height: 100px;
    background: red;
}

jsFiddle

有没有办法将红框放在上一行流中?我想避免修改标记。

这里的想法是元素应该在纵向和横向模式之间具有不同的布局,并且在纯 CSS 中做到这一点的唯一方法是使用带有 order 属性的 flexbox。据我所知,使用中间元素会锁定其子元素。

【问题讨论】:

  • 不确定我是否理解您要查找的内容是您正在尝试做的jsfiddle.net/pJy66/2 但它不是灵活的

标签: css flexbox


【解决方案1】:

这就是你要找的吗?

.foo {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  height: 200px;
}

.a, .c {
  flex: 0 0 50%;
  background: green;
}

.b {
  flex: 0 0 100%;
  order: 1;
  background: blue;
}
.c {
  background: red;
}

Quick codepen sample 带有 -webkit- 前缀

更新Tuned pen 横向/纵向比例

【讨论】:

  • 有没有办法在不设置 .foo 高度的情况下完成这项工作?
  • 这个答案太棒了,你知道是否有一个答案可以容纳任意数量的跨行吗?
  • @J__ 我觉得你可以写一些统计目标元素和维度的js,但我不确定你是否只能用css来管理。
  • Veiko:我将如何在 上应用它?原因是,出于 js 排序的原因,我需要使用传统表格,因此每个“列表”使用的 不能超过 1 个
  • @Andreyu 没有高度是不行的,所以基本没用...最好用float、tables或grid(但缺乏支持)
猜你喜欢
  • 2018-08-23
  • 2014-10-19
  • 1970-01-01
  • 2013-11-13
  • 1970-01-01
  • 2016-09-18
  • 2016-11-03
  • 2023-03-18
  • 1970-01-01
相关资源
最近更新 更多